1function numberWithCommas(x) {
2 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
3}
1// Convert a number to a string with commas
2function numberWithCommas(x) {
3 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
4}
5
6// Convert a number to a string with commas taking into account decimal point
7function numberWithCommasDecimal(x) {
8 return x.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");
9}