自留笔记,从其他博主处借鉴然后修改的。
function unifyNumber(num) {
if (num === '') {
return 0
} else {
let handleNum = parseFloat(num)
let isToFixed = handleNum.toString().includes('.') && handleNum.toString().split('.')[1].length > 2
if (isToFixed) {
if (handleNum.toFixed(2).toString().split('.')[1] == "00") {
return handleNum.toFixed(0)
} else {
return handleNum.toFixed(2)
}
} else {
return handleNum
}
}
}