javascript实现数字千位逗号分隔(xxx,xxxx)

tech2023-06-28  116

通过正则表达式进行转换

function sep2(n) { let str = n.toString() str.indexOf('.') < 0 ? str += '.' : void 0 return str.replace(/(\d)(?=(\d{3})+\.)/g, '$1,').replace(/\.$/, '') }

 

最新回复(0)