This article describes the method of converting numbers into capitalized integer amounts in JavaScript. Share it for your reference. The specific implementation method is as follows:
The code copy is as follows: function digit_uppercase(n) {
var digit = [
'zero', 'one', 'two', 'three', 'si',
'Wu', 'Lu', 'Qi', 'Ba', 'Nine'
];
var unit = [
['yuan', 'wan', 'wan'],
['', 'she', 'bai', 'qian']
];
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 % 10] + unit[1][j] + p;
n = Math.floor(n / 10);
}
s = p.replace(/(zero.)*zero$/, '')
.replace(/^$/, 'zero')
+ unit[0][i] + s;
}
return s.replace(/(zero.)*zero yuan/, 'yuan')
.replace(/(zero.)+/g, 'zero')
.replace(/^$/, 'zero yuan') + 'whole';
}
The test code is as follows:
Copy the code as follows: alert(digit_uppercase(0)); // Zero-yuan whole
alert(digit_uppercase(123)); // One hundred 23 yuan total
alert(digit_uppercase(1000000)); // One hundred million yuan
alert(digit_uppercase(100000001)); // One million yuan in total
alert(digit_uppercase(1000000000)); // One billion yuan
alert(digit_uppercase(1234567890)); // One, two, three, five, seven, eight, nine, nine, nine, all
alert(digit_uppercase(1001100101)); // One pick-up, one pick-up, one pick, one pick, one pick, one pick, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one, one
alert(digit_uppercase(110101010)); // One hundred thousand one thousand one thousand one thousand one thousand one thousand one thousand one thousand one thousand one whole
I hope this article will be helpful to everyone's JavaScript programming.