Copy codeThe 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;
}