SoFunction
Updated on 2025-03-01

JS numeric value converted to 3-bit comma separated sample code


function formatNum(strNum) {

if ( <= 3) {

return strNum;

}

if (!/^(\+|-)?(\d+)(\.\d+)?$/.test(strNum)) {

return strNum;

}

var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;

var re = new RegExp();

("(\\d)(\\d{3})(,|$)");

while ((b)) {

b = (re, "$1,$2$3");

}

return a + "" + b + "" + c;

}