Skip to content

Instantly share code, notes, and snippets.

@namomo
Last active February 4, 2017 10:04
Show Gist options
  • Save namomo/ed9aa19bbcd95bc226df002fbbaea07e to your computer and use it in GitHub Desktop.
Save namomo/ed9aa19bbcd95bc226df002fbbaea07e to your computer and use it in GitHub Desktop.
function addComma(val)
{
if (val === undefined) return '0';
var reg = /(^[+-]?\d+)(\d{3})/;
val += '';
while(reg.test(val)) {
val = val.replace(reg, '$1' + ',' + '$2');
}
return val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment