Skip to content
Advertisement

How to format Number to Currency without decimal point in JavaScript?

var computeST = 2145523
var resultFormat= <-- format the computeST here -->
alert(resultFormat);

the display alert should be

2,145,523

Anyone can help me?

Advertisement

Answer

Try this:

console.log(numberWithCommas(2145523));

function numberWithCommas(x) {
  return x.toString().replace(/B(?=(d{3})+(?!d))/g, ",");
}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement