Print number with commas as thousands separators in javascript - Node.js Number

Node.js examples for Number:Format

Description

Print number with commas as thousands separators in javascript

Demo Code



// Nice regex from  http://stackoverflow.com/questions/2901102/how-to-print-number-with-commas-as-thousands-separators-in-javascript
function addSep(numberString) {
  var parts = numberString.split('.');
  parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  return parts.join('.');
}

Related Tutorials