Last active
December 9, 2015 23:18
-
-
Save composite/4343031 to your computer and use it in GitHub Desktop.
just format a number. (e,g 40000000 -> 40,000,000)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function numberFormat(n){ | |
| if(isNaN(+n)||+n<1e3) return n; | |
| n=n+'';var s='';for(var i=n.length-1;i>=0;i--) s+=n.charAt(i);n=''; | |
| for(var i=s.length-1;i>=0;i--) n+=s.charAt(i)+(!(i%3)?',':''); | |
| return n.replace(/,$/,''); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment