Posted By

Tmeister on 08/14/10


Tagged

number format separator comma


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

StrawMan
shalomfriss
PixelJuice
albertomori


Formating numbers comma separator


 / Published in: ActionScript 3
 

URL: http://klr20mg.com

Format number using a comma as a separator

  1. function formatNumber(number:Number):String
  2. {
  3. var nString:String = String(number)
  4. var rst:String = ''
  5. while (nString.length > 3)
  6. {
  7. var pcs:String = nString.substr(-3)
  8. nString = nString.substr(0, nString.length - 3)
  9. rst = ',' + pcs + rst
  10. }
  11. return (nString.length) ? rst = nString + rst : rst
  12. }

Report this snippet  

You need to login to post a comment.