numberFormat.js 387 B

123456789101112
  1. module.exports = function numberFormat(number, dec, dsep, tsep) {
  2. if (isNaN(number) || number == null) return '';
  3. number = number.toFixed(~~dec);
  4. tsep = typeof tsep == 'string' ? tsep : ',';
  5. var parts = number.split('.'),
  6. fnums = parts[0],
  7. decimals = parts[1] ? (dsep || '.') + parts[1] : '';
  8. return fnums.replace(/(\d)(?=(?:\d{3})+$)/g, '$1' + tsep) + decimals;
  9. };