Get the App
SLTechnology News&Howtos  ›  Development  › 

How to change Digital amount to uppercase amount by JS

Shulou Source: shulou.com Published: 2022-06-03 09:50:16 09月28日 Update

Editor to share with you JS how to achieve the digital amount to capitalize the amount, I hope you will gain something after reading this article, let's discuss it together!

The way js capitalizes the amount number

FunctiondigitUppercase (price) {

Constfraction= ['horn', 'minute']

Constdigit= ['zero', 'one','II','3', 'restaurant','Wu','Lu','Qi', 'Qing', 'nine']

Constunit= [

['Yuan', 'Wan', 'billion']

[', 'pick', 'Bai', 'Qian']

]

Letnum=Math.abs (price)

Lets=''

Fraction.forEach ((item,index) = > {

Replace = (digit [Math.charts (num*10* (10**index))] + item) .swatch (/ zero. /,'')

})

The amount number is changed to an uppercase code.

Swatches | | 'whole'

Num=Math.floor (num)

For (leti=0;i0;i+=1) {

Letp=''

For (letj=0;j0;j+=1) {

P=digit [num] + unit [1] [j] + p

Num=Math.floor (num/10)

}

S=p.replace (/ (zero.) * zero $/,'). Replace (/ ^ $/, 'zero) + unit [0] [I] + s

}

Returns.replace (/ (zero.) * zero yuan /, 'yuan'). Replace (/ (zero.) + / g minus' zero'). Replace (/ ^ integer $/, 'zero integer')

}

After reading this article, I believe you have a certain understanding of "how to convert digital amount to capitalized amount in JS". If you want to know more about it, welcome to follow the industry information channel. Thank you for your reading!

Tags: Amount uppercase number article zero yuan code finished way more knowledge industry information information channel channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei Shulou Information Redmi Xiaomi