Formating numbers comma separator


/ Published in: ActionScript 3
Save to your folder(s)

Format number using a comma as a separator


Copy this code and paste it in your HTML
  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. }

URL: http://klr20mg.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.