Answers for "print a number with commas as thousands separator"

0

print a number with commas as thousands separator

Example: 10000000.2345 -> '1,000,000.2345'
function numberWithCommas(x) {
    var parts = x.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
}
Posted by: Guest on October-19-2021

Code answers related to "print a number with commas as thousands separator"

Code answers related to "Javascript"

Browse Popular Code Answers by Language