-
Adding space after 3 numbers
Hi, I’m working on a project where I need to display a number, with a space between numbers every 3 characters.
So, for example:
300
30 000
300 000
300 000 000
etc.Now I have to following code to add a comma to the numbers, if I try to replace ‘,’ with ‘ ‘ though, I get a syntax error. Any suggestions for workarounds?
var toDisplay = comp("00_input").layer("cijfer_3_1")("Text")("Source Text").value;var num = toDisplay;
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;
}