The example in this article describes how JavaScript converts numbers to uppercase in integer amounts. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
function Digit_uppercase (n) {
var digit = [
' 0 ', ' one ', ' II ', ' three ', ' Restaurant ',
' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU '
];
var unit = [
[' Yuan ', ' million ', ' billion '],
[', ' Pick ', ' bai ', ' thousand ']
];
var s = ';
for (var i = 0; i < unit[0].length && n > 0; i++) {
var p = ';
for (var j = 0; J < unit[1].length && n > 0; j +) {
p = digit[n%] + unit[1][j] + p;
n = Math.floor (N/10);
}
s = p.replace (/(0.) * 0 $/, "")
. replace (/^$/, ' 0 ')
+ Unit[0][i] + s;
}
Return S.replace (/(0) * 0 yuan/, ' yuan ')
. Replace (/(0.) +/g, ' 0 ')
. replace (/^$/, ' 0 yuan ') + ' whole ';
}
The test code is as follows:
Copy Code code as follows:
Alert (digit_uppercase (0)); 0 Yuan Whole
Alert (Digit_uppercase (123)); I'll pick up a three-dollar whole
Alert (Digit_uppercase (1000000)); hundred million Yuan whole
Alert (Digit_uppercase (100000001)); One billion zero one yuan whole
Alert (Digit_uppercase (1000000000)); A billion-dollar whole
Alert (Digit_uppercase (1234567890)); I picked up a few million thousand thousands of Ba thousand Qi Nine to pick up the whole
Alert (Digit_uppercase (1001100101)); One to pick up billion zero one hundred million zero one hundred 0 one yuan whole
Alert (Digit_uppercase (110101010)); One billion thousand 0 one to pick up million thousand 0 a yuan whole
I hope this article will help you with your JavaScript programming.