0 points

formatting - How to print a number with commas as thousands separators in JavaScript - Stack Overflow


dashboard

Tue Aug 18 2020 15:41:54 GMT+0000 (UTC)

Posted by @rdemo #javascript

function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
content_copy Copy

https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript