Just a handy snippet I pinched:
function addCommaInNumber (number : Number) : String { var integer : String = "" ; var fraction : String = "" ; var string : String = number.toString(); var array : Array = string.split("."); var regex : RegExp = /(\d+)(\d{3})/; integer = array[0]; while( regex.test(integer) ) { integer = integer.replace(regex,'$1' + ',' + '$2'); } if (array[1]) { fraction = integer.length > 0 ? '.' + array[1] : ''; } return integer + fraction; } function removeCommaInNumber (string : String) : Number { var regex : RegExp = /,/g; return Number (string.replace(regex,"")) ; }
Tech Reference: AS3
Leave a Reply