Tuesday, 28 November 2023

Javascript how to add comma to numbers

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


1000 => 1,000

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

No comments:

Post a Comment