FL MX - Formatting numbers to comma separate 1000's

Hi

I have a bunch of text fields that display numbers such as 2745345

What i want is a neat bit of code that quickly and simply converts this to 2,745,345

This makes the numbers more easy to read and interpret.

Has anyone got a neat way of doing this?

Any help most gratefuly received

Cheers

John :slight_smile:

:sigh:

http://proto.layer51.com/d.aspx?f=164#c545

this is fun too :wink:
http://proto.layer51.com/d.aspx?f=622

luv those string manipulations…


Number.prototype.addCommas = function(n){
	n = this.toString();
	var l = n.length;
	var a = [];
	while((l-=3)>0){
		a.unshift(n.substr(l,3));
	}
	a.unshift(n.substr(0,3+l));
	return a.join(",");
}

n = 427453458492;
trace(n.addCommas());
// traces 427,453,458,492 (as a string)

Marvellous - all examples led me to a solution - thanks one and all

John :beam: