Answers for "how to print a number with commas as thousands separators in jquery?"

8

How to print a number with commas as thousands separators in JavaScript

function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
Posted by: Guest on July-29-2020
0

jquery thousand separator

function addCommas(nStr) {
    nStr += '';
    var x = nStr.split('.');
    var x1 = x[0];
    var x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
Posted by: Guest on April-18-2021

Code answers related to "how to print a number with commas as thousands separators in jquery?"

Code answers related to "Javascript"

Browse Popular Code Answers by Language