金额数字隔三位加逗号

filters: {
countFormat (num) {
let strNum = num + ''
let mod = strNum.length % 3
let output = (mod === 0 ? '' : (strNum.substring(0, mod)))
for (let i = 0; i < Math.floor(strNum.length / 3); i++) {
if ((mod === 0) && (i === 0)) {
output += strNum.substring(mod + 3 * i, mod + 3 * i + 3)
} else {
output += ',' + strNum.substring(mod + 3 * i, mod + 3 * i + 3)
}
}
return output
}
},

你可能感兴趣的:(金额数字隔三位加逗号)