小編給大家分享一下JS如何實(shí)現(xiàn)數(shù)字金額轉(zhuǎn)大寫金額,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
js將金額數(shù)字轉(zhuǎn)大寫的方式
functiondigitUppercase(price){
constfraction=['角','分'];
constdigit=['零','壹','貳','叁','肆','伍','陸','柒','捌','玖'];
constunit=[
['元','萬(wàn)','億'],
['','拾','佰','仟'],
];
letnum=Math.abs(price);
lets='';
fraction.forEach((item,index)=>{
s+=(digit[Math.floor(num*10*(10**index))%10]+item).replace(/零./,'');
});
金額數(shù)字轉(zhuǎn)大寫代碼
s=s||'整';
num=Math.floor(num);
for(leti=0;i
letp='';
for(letj=0;j
p=digit[num%10]+unit[1][j]+p;
num=Math.floor(num/10);
}
s=p.replace(/(零.)*零$/,'').replace(/^$/,'零')+unit[0][i]+s;
}
returns.replace(/(零.)*零元/,'元').replace(/(零.)+/g,'零').replace(/^整$/,'零元整');
}
看完了這篇文章,相信你對(duì)“JS如何實(shí)現(xiàn)數(shù)字金額轉(zhuǎn)大寫金額”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!