怎样用js实现千位分隔符?
—
正则 + replace
function commafy(num) {
num = num + '';
var reg = /(-?d+)(d{3})/;
if (reg.test(num)) {
num = num.replace(reg, '$1,$2');
}
return num;
}
We use cookies to understand our websites traffic and offer our website visitors personalized experience. To find out more, click ‘More Information’. In addition, please, read our
Privacy policy.