let number =50000000;
let new_number = number / 10000;
console.log('formatter-new_number===', new_number);
return new_number.toFixed(2) + '万';
会发现整数使用toFixed(2),之后会有多余的.00
let number =50000000;
let new_number = number / 10000;
console.log('formatter-new_number===', new_number);
new_number = unifyNumber(new_number) + '万';
//独立的保留两位小数的方法
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) {
return handleNum.toFixed(2)
} else {
return handleNum
}
}
}
效果图如下: