js 将金额每隔3加逗号 数字千分位

时间:2020-10-20 11:08:56   收藏:0   阅读:130

技术分享图片

 

 

// 数字千分位
export function toThousands(num) {
var num = (num || 0).toString(), result = ‘‘;
// 将传入数据转换为字符串
while (num.length > 3) {
// 只要字符串长度大于三就执行
result = ‘,‘ + num.slice(-3) + result;
// 将字符串后三位裁剪并加入最终的字符串
num = num.slice(0, num.length - 3);
// 更新字符串长度
}
if (num) { result = num + result; }
return result;
}

原文:https://www.cnblogs.com/web-aqin/p/13844929.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!