JavaScript converts a number to an integer amount of capital capitalization method _javascript Tips

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.