Currency Formatter

I was working on a prototype application and it needed currency formatter since it displays a ton of data. I figured that I would create one and here it is.


/**
* NumberFormatter class
* Author: Shinhee Kim @shinstudio.com
* Last Updated: Feb 03, 2006
**/

class com.shinstudio.formatter.NumberFormatter {

static function setCurrencyFormat(strNumber:String, currencySign:String):String {
var c = strNumber.indexOf(".");
var t = c != -1 ? strNumber.split(".")[0] : strNumber;
var cent = c != -1 ? strNumber.split(".")[1] : "";
var nums = [];
var num = t.length;
var finalNum = currencySign==null ? "" : currencySign;
for (var i = 1; i=0) {
finalNum += num == 0 ? nums[num] : nums[num]+",";
num--;
}
return c != -1 ? finalNum+"."+cent : finalNum;
}

}

  • Trackback are closed
  • Comments (2)
    • Simon Wacker
    • February 3rd, 2006 11:03am

    Hi Shinhee,

    nice lightweight formatter!

    The as2lib team is currently working on a NumberFormat (based on the one from Java: http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html ) that will also support localized currency formatting.

    It may be interesting for you for your next project. ;)

    Greetings,Simon

    • sh.kim
    • February 8th, 2006 8:24am

    Hi Simon,I hope I can do flash projects. I’m pretty sure the project I used flash for is the last one. Also it wasn’t real project but prototype. : ( When I have a real flash project, I’ll definitely look for your framework as2lib. I knew about your guys’ awesome work before.

Comment are closed.