Sample Code for converting the RMB amount into uppercase in JS

Source: Internet
Author: User

Sample Code for converting the RMB amount into uppercase in JS

This article mainly introduces the sample code for converting the RMB amount into uppercase using JS. If you need it, you can refer to it for help.

The Code is as follows:

// Convert the RMB amount to the capital program in JavaScript

// CopyRight Bardo QI

 

Function numToCny (num ){

Var capUnit = ['000000', '000000', '000000', 'cn', ''];

Var capDigit = {2: ['angular ', 'quantity', ''], 4: ['quantity', 'quantity', 'snapshot','']};

Var capNum = ['0', 'yi', 'er', 'san', 'siz', 'wu', 'lu', 'weight', 'weight ', 'signature'];

If (num. toString (). indexOf ('.')> 16) | (isNaN (num )))

Return '';

Num = (Math. round (num * 100)/100). toString ();

Num = (Math. pow (10, 19-num. length). toString (). substring (1) + num;

Var I, ret, j, nodeNum, k, subret, len, subChr, CurChr = [];

For (I = 0, ret = ''; I <5; I ++, j = I * 4 + Math. floor (I/4 )){

NodeNum = num. substring (j, j + 4 );

For (k = 0, subret = '', len = nodeNum. length; (k <len) & (parseInt (nodeNum. substring (k ))! = 0); k ++ ){

CurChr [k % 2] = capNum [nodeNum. charAt (k)] + (nodeNum. charAt (k) = 0 )? '': CapDigit [len] [k]);

If (! (CurChr [0] = CurChr [1]) & (CurChr [0] = capNum [0])

If (! (CurChr [k % 2] = capNum [0]) & (subret = '') & (ret = '')))

Subret + = CurChr [k % 2];

}

SubChr = subret + (subret = '')? '': CapUnit [I]);

If (! (SubChr = capNum [0]) & (ret = '')))

Ret + = subChr;

}

Ret = (ret = '')? CapNum [0] + capUnit [3]: ret;

Return ret;

}

 

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.