Number format in table in calculation field
Can anyone tell me how to format the money amount in my calculation field table? I need to show the amount ("montant") as CHF 17'884.80
I'm sure this is easy for some of you...;)
-
A tip: If you need to format not only one number (e.g. if you have a table with number values in multiple columns) you don't need to repeat
"CHF" + variable[i].toFixed(2).replace(...).replace(...) for each variable. You can use a function:function formatNum(number){
if (typeof number === "undefined" || number == null || number== "NaN" ) number = 0;
return "CHF " + number.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, "'")
};Put that function code somewhere above the for-loop.
Then call the function wherever you need it to format a number as amount, e.g.lines.push(numCur(variable1[i]) + " | " + numCur(variable2[i]) + " | " + numCur(variable3[i]));
Btw. The first .replace(".",".") in your code you can remove cause it doesn't make sense to replace a dot with a dot :)
Rainer
Please sign in to leave a comment.
Comments
3 comments