千分符N种方式

70 阅读1分钟
var reg = /(?!^)(?=(\d{3})+$)/g
var reg1 = /(\d)(?=(\d{3})+(?!\d))/g
var reg2 = /(?=\d)(?=(\d{3})+(?!\d))/g
var func = num => num.toString().replace(reg,',')
var func1 = num => num.toString().replace(reg1,'$1,')
var func2 = num => num.toString().replace(reg2,',')