JS - add Comma to number and remove decimal

0 votes
220 views
added Mar 19, 2018 in Javascript by LC Marshal Captain (25,790 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

 

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