Skip to content

Instantly share code, notes, and snippets.

View mahalie's full-sized avatar

mahalie mahalie

View GitHub Profile
@mahalie
mahalie / jquery.commafy.js
Created March 7, 2012 21:25
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;
}