JavaScript
x
4
1
var computeST = 2145523
2
var resultFormat= <-- format the computeST here -->
3
alert(resultFormat);
4
the display alert should be
2,145,523
Anyone can help me?
Advertisement
Answer
Try this:
JavaScript
1
5
1
console.log(numberWithCommas(2145523));
2
3
function numberWithCommas(x) {
4
return x.toString().replace(/B(?=(d{3})+(?!d))/g, ",");
5
}