Post

2 followers Follow
0
Avatar

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...;)

 



Richard Hedger (Niton)

Please sign in to leave a comment.

3 comments

0
Avatar

Solved it myself - here's an example solution with the result. Note the use of hyperlinks to relevant documents in related apps

Richard Hedger (Niton) 0 votes
0
Avatar

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

Rainer Grabowski 0 votes