add comma to number javascript
snippet in javascript

add comma to number javascript

user9016

var n = 34523453.345
n.toLocaleString()
"34,523,453.345"

javascript friendly number format with commas

user455

//ES6 Way
const numberWithCommas = (x) => {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

how to format an integer with a comma in javascript

user8784

x.toString().toLocaleString(); // x must be a number