我写在了过滤器里面了,方便全局使用
// 格式化数字三位加一逗号 (为0显示)
Vue.filter('numberPutCommaShow', value => {
let installVal = value;
if(value != ''){
value = Number(value).toFixed(2)
let intPart = Math.trunc(value)// 获取整数部分
let intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断
let floatPart = '.00' // 预定义小数部分
let value2Array = value.split('.')
// =2表示数据有小数位
if(value2Array.length === 2) {
floatPart = value2Array[1].toString() // 拿到小数部分
if(floatPart.length === 1) { // 补0,实际上用不着
return intPartFormat + '.' + floatPart + '0'
} else {
if(installVal < 0 && intPar