function numFormat(num, field) {
// 数值添加单位
num *= 1 // 转换数值
let unit = ''
if (num < 10000) {
if (field && field.indexOf('次数') !== -1) {
unit = '次'
} else {
unit = '个'
}
} else if (num < 100000000) {
unit = '万'
num = (num / 10000)
.toFixed(2)
.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
} else {
unit = '亿'
num = (num / 100000000)
.toFixed(2)
.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
}
return num + unit
}
numFormat(173263428429)
// 1,732.63亿