Number Format – Thousand Separator in AS3

Here’s a short number format function I wrote to easily paste in your code when needed. It’s really handy for currency formatting.
The first parameter (number:*) can be a Number, int, uint or a String class instance.
The last parameter (siStyle:Boolean) specifies whether to use the International System of Units or not. SI units have points between the thousands and a comma for the seperator (123.456.789,01). Putting siStyle as false reverses that behaviour (123,456,789.01).

It’s really ugly by design since I wanted it to be a single, tiny function. There’s loads of prettier/faster code samples out there.

This entry was posted
on Wednesday, August 12th, 2009 at 21:25 and is filed under AS3, Flash.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

nice functionality but I hate your formatting. It isn’t clear enough to be updated easily. You don’t need to show that you can program like a nasa guy when you give a function on the web. Most people who will use your function will be beginners…
But thank you for sharing it

The formatting was done on purpose. I know it’s massively compressed and horrible to read, but it’s supposed to be small and convenient to paste into timeline or code. There were other resources which had dedicated classes which are easily changeable and commented (like for beginners) at the time I made this (and still are), but I didn’t want a whole class when I just wanted something quick and small to insert into the timeline.
I also don’t recommend this code for mass number processing since it is not at all optimized for speed, only compactness.