-
commas and decimal points in source text expression
I’m using an expression to add commas to numbers but I also want to add a decimal point and two fixed decimal integers.
This is the expression I am using. Can anyone help?
var num = thisComp.layer("dummy").text.sourceText;
num = Comma(num);
[num]function Comma(number)
{
number = '' + Math.round(number);
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}