Skip to content

Instantly share code, notes, and snippets.

@XDestination
XDestination / number.withThousandSep.js
Created September 25, 2018 10:33
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;