Skip to content

Instantly share code, notes, and snippets.

@kaimallea
Created November 29, 2011 18:03
Show Gist options
  • Save kaimallea/1405745 to your computer and use it in GitHub Desktop.
Save kaimallea/1405745 to your computer and use it in GitHub Desktop.
Add commas (or your own separator) to numbers
function separateNumbers (n, sep) {
n = n.toString().split('');
var i = n.length - 3;
for (; i > 0; i-=3) {
n.splice(i, 0, (sep ? sep : ','));
}
return n.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment