千分位正则(Vue)
//判断是否是千分位数字,或非数字
const formatThousand2 = (val) => {
if (val == null) {
return val = '0.00'
} else {
let valString = val.toString().replace(/,/g, "")
if ((isNaN(parseFloat(valString)) || valString.trim() == "" || !isFinite(valString))) {
return val = '0.00'
} else {
// 是数字转为千分位格式
return val = (parseFloat(valString).toFixed(2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
}
}
}
//千分位转number
const formatNumber = (val) => {
if (val == null) {
return val = '0.00'
} else {
return val.replace(/,/g, '');
}
}

浙公网安备 33010602011771号