Skip to content

Instantly share code, notes, and snippets.

@mahalie
Created March 7, 2012 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mahalie/1996338 to your computer and use it in GitHub Desktop.
Save mahalie/1996338 to your computer and use it in GitHub Desktop.
jQuery commafy
/* COMMAFY
* Simple helper function to add commas to any number
* Requires jQuery, via @cowboy
*/
function commafy(n) {
var n = n || 0;
n = (n+'').split('.').map(function(s,i){return i?s:s.replace(/(\d)(?=(?:\d{3})+$)/g,'$1,')}).join('.');
return n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment