js脚本function: //js数字千分符处理 function commafy(num) { num = num + ""; var re = /(-?\d+)(\d{3})/ while (re.test(num)) { num = num.replace(re, "$1,$2") } return num; }…
//js数字千分符处理 function commafy(num) { num = num + ""; var re = /(-?\d+)(\d{3})/ while (re.test(num)) { num = num.replace(re, "$1,$2") } return num; } 执行下,效果不错,收藏记录…
JS数字千分: 1.例子:1000--->1,000 2.实现如下: salesToFormat: function (num) { var num = (num || 0).toString(), result = ''; while (num.length > 3) {//拿掉num的最后三位给result result = ',' + num.slice(-3) + result; num = num.slice(0, num.length - 3); } if (num) { resu…
一般在JavaScript中实现千分符,是使用切割+连接一顿操作 这里尝试一下使用正则快速实现千分符 let num0 = '12' let num1 = '123' let num2 = '1234' let num3 = '123456789' let num4 = '1234567890' let num5 = '12345678901' let num6 = '123456789012' let num7 = '1234567890123' let r0 = num0.replace(/…