Skip to content

Instantly share code, notes, and snippets.

@XDestination
Created September 25, 2018 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XDestination/bd75bb913ab8f4bf169facc502d2a95d to your computer and use it in GitHub Desktop.
Save XDestination/bd75bb913ab8f4bf169facc502d2a95d to your computer and use it in GitHub Desktop.
format a number with thousand separators
Number.prototype.withThousandSep = function() {
return (this + '')
.split('')
.reverse()
.reduce(function(carry, d, index) {
if (index > 0 && index % 3 === 0) {
carry.push('.');
}
carry.push(d);
return carry;
}, [])
.reverse()
.join('');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment