js数字以三位逗号隔开 不足三位不加,超出都适合
let userComma = 999999
let userCommaLang = userComma.toString().length;
let userItem = "";
let frot,userCommaDot;
if (userCommaLang > 3) {
userComma = userComma.toString();
userCommaDot = userCommaLang / 3;
userCommaDot = Math.ceil(userCommaDot);
for (let i = 1; i < userCommaDot; i++) {
frot = (i - 1) * 3;
userItem += userComma.substr(frot, 3) + ",";
if (userCommaDot - i == 1) {
frot = i * 3;
userItem += userComma.substr(frot, length);
}
}
console.log(userItem )
} else {
console.log(userItem )
}
js数字以三位逗号隔开
最新推荐文章于 2021-12-16 15:13:06 发布