为数字添加千分符
- 查找一个“非单词边界”
- [1]后面伴随着“3的倍数个数字”
- [2]后面伴随着一个“单词边界”
/\B(?=(\d{3})+\b)/
把查找到的“非单词边界”替换成千分符即可
'32132112345123136.123'.replace(/\B(?=(\d{3})+\b)/g,',')
"32,132,112,345,123,136.123"
缺陷:小数位同样会被处理
'32132112345123136.123123123123'.replace(/\B(?=(\d{3})+\b)/g,',')
"32,132,112,345,123,136.123,123,123,123"