I’m using code I found on this site to add commas to a large number (so that a number like 1000000 appears as 1,000,000). Below is the actionscript I’m using.
When I define the variable debt as any number, the script works perfectly. But if I define debt as a variable passed to the movie from a PHP file, then the script puts the commas in the wrong places (i.e., 10,000,00). Can anyone explain to me why this would happen, and how to fix it?
var input = debt;
var inputString = input.toString();
var finalString = “$”;
var count = 0;
var tempString = “”;
for (var i = inputString.length-1; i>=0; i–) {
count++;
tempString += inputString.charAt(i);
if ((count%3 == 0) && (i - 1 >= 0)) {
tempString += “,”;
}
}
for (var k = tempString.length; k>=0; k–) {
finalString += tempString.charAt(k);
}
return(finalString);