Skip to content

Instantly share code, notes, and snippets.

@composite
Last active December 9, 2015 23:18
Show Gist options
  • Select an option

  • Save composite/4343031 to your computer and use it in GitHub Desktop.

Select an option

Save composite/4343031 to your computer and use it in GitHub Desktop.
just format a number. (e,g 40000000 -> 40,000,000)
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