<div class="trad top_text">
{{ count | formatNumber(4, false, true) | formatMoney }}
</div>
// 格式化数字精度 val , precision 精度 ,isRound true 向上取值,false 向下取值,isWithOutZero:末尾是否包含0
formatNumber(val, precision, isRound = false, isWithOutZero = false) {
if (
typeof val === 'undefined' ||
val === null ||
Number(val) === Infinity ||
isNaN(val) ||
val === 0 ||
val === '0' ||
Number(val) === 0
) {
val = 0
}
try {
let num = Big(Number(val))
.round(precision, isRound ? 3 : 0)
.toFixed(precision)
if (isWithOutZero) {
const arr = String(num).split('.')
if (arr.length > 1 && arr[1] !== '') {
const right = arr[1].replace(/0+$/, '')
num = `${arr[0]}${right ? '.' + right : ''}`
}
}
return num
} catch (err) {
return val
}
},
// 格式化数值,1000=》1,000
formatMoney(num) {
const res = num.toString().replace(/\d+/, function (n) {
return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) {
return $1 + ','
})
})
return res
},