若有问题还请多多指教~含补位.00
export function formatMoney(){
let moneyNum
if((money??'')!==''){
money=money.toString()
if(money===''){
moneyNum=''
}else if(money==='0'){
moneyNum='0.00'
}else{
if(money.indexOf('.') != -1){
let formatNum=money.split('.');
if(formatNum.length==2){
let decimal=formatNum[1].toString();
let integer=formatNum[0];
if(decimal.length==1){
moneyNum=`${String(integer).replace(/\B(?=(\d{3})+(?!\d))/g,',')}.${decimal}0`
}else{
moneyNum=`${String(integer).replace(/\B(?=(\d{3})+(?!\d))/g,',')}.${decimal}`
}
}else{
moneyNum=`${String(money).replace(/\B(?=(\d{3})+(?!\d))/g,',')}.00`
}
}else{
moneyNum=`${money}.00`
}
}
}else{
moneyNum=''
}
return moneyNum
}
金额格式化千分位展示
于 2023-11-10 14:40:51 首次发布