Skip to content

Instantly share code, notes, and snippets.

View alanleite's full-sized avatar

Alan Leite alanleite

View GitHub Profile
@alanleite
alanleite / format.js
Created April 23, 2018 13:54
Format real
export function format(value, n, x, s, c) {
if (!value) return ''
var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
num = value.toFixed(Math.max(0, ~~n));
return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
};