Javascript is perfectly compatible with the conversion of RMB and case in various browsers. js is case-sensitive.

Source: Internet
Author: User

Javascript is perfectly compatible with the conversion of RMB and case in various browsers. js is case-sensitive.

/* Convert lowercase letters to uppercase letters */

var xcc= "12.22";document.write(xcc+"=>"+formatRMB(xcc)+"<br/>");

/* Convert uppercase to lowercase */

Var rrrr = ""; document. write (rrrr + "=>" + parseRMB (rrrr ));

Output result:
12.22 => pick up the bonus points
I just picked up the bonus points => 12.22

Let's take a look at the specific instance

Var c = "". split (""); // ["zero", "one", "two", "three", "Si", "Wu", "Lu ", "inline", "inline", "inline"] var _ c = {}; // reverse correspondence for (var I = 0; I <c. length; I ++) {_ c [c [I] = I ;}; var d = "RMB *** million "; var e = ", pick up, quit, quit ". split (","); function unit4 (arr) {var str = "", I = 0; while (arr. length) {var t = arr. pop (); str = (c [t] + (t = 0? "": E [I]) + str; I ++;} str = str. replace (/[zero] {2,}/g, "zero"); str = str. replace (/^ [0]/, ""); str = str. replace (/[0] $/, ""); if (str. indexOf ("zero") = 0) {str = str. substring (1);} if (str. lastIndexOf ("zero") = str. length-1) {str = str. substring (0, str. length-1);} return str;} function _ formatD (a) {// convert the integer part var arr =. split (""), I = 0, result = ""; while (arr. length) {var arr1 = arr. splice (-4, 4); var dw = d. charAt (I), unit = unit4 (arr1); if (dw = 'wan '&&! Unit) {dw = "";} result = unit + dw + result; I + = 4;} return result = "Yuan "? "": Result;} function _ formatF (B) {// convert fractional part B = B | ""; switch (B. length) {case 0: return "integer"; case 1: return c [B] + ""; default: return c [B. charAt (0)] + "" + c [B. charAt (1)] + "points" ;}} function _ format (n) {var a = ("" + n ). split (". "), a0 = a [0], a1 = a [1]; return _ formatD (a0) + _ formatF (a1);} function parse4 (u4) {var res = 0; while (t =/([]) ([]?) /G.exe c (u4) {var n = _ c [t [1], d = {": 1," pick up ": 10," success ": 100, "outputs": 1000} [t [2]; res + = n * d; u4 = u4.replace (t [0], "");} var result = ("0000" + res); return result. substring (result. length-4);} function _ parseD (d) {var arr = d. replace (/[0]/g ,""). split (/[trillion]/), rs = ""; for (var I = 0; I <arr. length; I ++) {rs + = parse4 (arr [I]) ;}; return rs. replace (/^ [0] +/, "") ;}; function _ parseF (f) {Var res = "", t = f. replace (/[^] +/g ,""). split (""); // remove the unit if (t. length) {res = ". ";}else {return" ";}; for (var I = 0; (I <t. length & I <2); I ++) {res + = _ c [t [I] ;}; return res ;}; function _ parse (RMB) {var a = RMB. split ("Yuan"), a1 = a [1], a0 = a [0]; if (. length = 1) {a1 = a0; a0 = "";} return _ parseD (a0) + _ parseF (a1 );}; // function formatRMB (num) {var n = Number (n Um); if (! IsNaN (num) {if (num = 0) {return "Zero yuan integer" ;}else {return _ format (n) ;}} else {return false ;}} // converts the upper case to lower case function parseRMB (RMB) {if (/^ [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)] {2,} $ /. test (RMB) {var result = _ parse (RMB); return RMB = this. formatRMB (result )? Result: result + "(?) ";}Else {return false ;};/* lowercase to uppercase */var xcc =" 12.22 "; document. write (xcc + "=>" + formatRMB (xcc) + "<br/>");/* convert uppercase to lowercase */var rrrr = ""; document. write (rrrr + "=>" + parseRMB (rrrr ));

Let's look at an example of converting RMB to uppercase.

// Convert the RMB amount to the upper-case JavaScript version // CopyRight Bardo QI function numToCny (num) {var capUnit = ['000000', '000000', '000000', 'cn ', '']; var capDigit = {2: ['angular ', 'quantity',''], 4: ['handler ', '']}; var capNum = ['0', 'yi', 'er', 'san', 'siz', 'wu', 'lu ', 'handler', 'handler', 'handler']; if (num. toString ()). indexOf ('. ')> 16) | (isNaN (num) return ''; num = (Math. role (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 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.