Are you first timer at Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - add Comma to number and remove decimal

0 votes
added Mar 19, 2018 in Javascript by LC Marshal Captain (25,880 points)
edited Jul 13, 2018 by LC Marshal
numberWithCommas: function(x) {
  return x.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",");

//e.g .00
return x.toFixed(2) //----> output 10,000.00

//e.g .0
return x.toFixed(1) //----> output 10,000.0


Please log in or register to response this reference. - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.