// 整数千分位添加逗号
function toThousands(num) {
num = num.toString()
let result = '';
while (num.length > 3) {
result = ',' + num.substring(num.length - 3) + result;
num = num.substring(0, num.length - 3);
}
result = num + result;
return result;
}
效果如图: