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

JS - add Comma to number and remove decimal

0 votes
12 views
added Mar 19, 2018 in Javascript by LC Marshal Lieutenant (17,190 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.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...