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; } 执行下,效果不错,收藏记录…
一般在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(/…