Skip to content

Instantly share code, notes, and snippets.

@XDestination
XDestination / number.withThousandSep.js
Created Sep 25, 2018
format a number with thousand separators
View number.withThousandSep.js
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;