如何给一串数字用千分制表示?比如9999999999变成9,999,999,999
'99999999999'.replace(/d{1,3}(?=(d{3})+$)/g, '$&,')
有小数点的'99999999999.02'做千分之转换
'99999999999.02' 输出"99,999,999,999.02"
'99999999999.33333333' 输出"99,999,999,999.33,333,333"
方法一
'99999999999.33333333'.replace(/d{1,3}(?=(d{3})+(?:.d+)?$)/g, '$&,')
方法二
"123456789.12123".replace(/(?!^)(?=(d{3})+(?:.d+)?$)/g, ',')
参考链接:
https://juejin.im/post/5d1702ed6fb9a07ef1619796?utm_source=wechat&from=groupmessage