4 Replies Latest reply on Apr 20, 2006 11:55 PM by dasura

# formatting numbers 1000-&gt;1.000

Hi everyone!

Im doing a calculator and I want the numbers readable. Instead of 100000 I want 100,000. I found another post on this forum with the following enclosed code. However the code doesnt work...could someone take a look? Thank you all!!

// formats a number
var myArray:Array = new Array(Math.ceil(money.length/3));
for (var i = 0; i<myArray.length; i++) {
var s = money.length-((i+1)*3);
var e = money.length-(i*3);
if (s<0) {
s = 0;
}
myArray = money.slice(s, e);
}
myArray.reverse();
var newVal:String = "";
for (var j = 0; j<myArray.length; j++) {
newVal += myArray[j];
if (j != myArray.length-1) {
newVal += ",";
}
}
var formatedPrice = newVal;
return formatedPrice;
}
// returns 30,000
• ###### 1. Re: formatting numbers 1000-&gt;1.000
try this maybe?

• ###### 2. formatting numbers 1000-&gt;1.000
sneakyimp, thank you! Just what I wanted.
• ###### 3. Re: formatting numbers 1000-&gt;1.000
great! it doesn't handle negative numbers. you might want to test it out on various numbers first because i haven't.
• ###### 4. Re: formatting numbers 1000-&gt;1.000
Ok... there is a little thing thats not right... try this
trace(numberFormat(500.1234));

the result will be ",500.1234"...the comma before the 500.
I can live with this but if you have an easy solution for this I will be most thankful! cu!