Node.js examples for Number:Format
Format number with comma
/**/*from ww w . j a v a2s.co m*/ * Format number with comma * @type {string|number} x */ function addCommas(x) { if (isNaN(x)) { return '-'; } x = (x + '').split('.'); return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,'$1,') + (x.length > 1 ? ('.' + x[1]) : ''); }