Javascript to convert the form of RMB capital _ javascript skills

Source: Internet
Author: User
This article mainly gives you detailed information on how to convert the amount of RMB in Javascript. For more information, see the example in this article, for your reference, the specific content is as follows:

Function convertCurrency (num) {// convert it to the capital amount of RMB in the form of var str1 = '0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 '; // The Chinese Character var str2 corresponding to 0-9 = 'Ten thousand yuan (hundreds of millions of yuan) and ten thousand yuan (hundreds of thousands of yuan); // The Chinese Character var str3 corresponding to the digit; // The var str4 value obtained from the original num value; // The string form of the number var str5 = ''; // The capital form of the Renminbi var I; // The variable var j; // The value of num is multiplied by the string length of 100. // the Chinese-speaking var ch2 of numbers; // The Chinese-reading var nzero of numbers = 0; // used to calculate the continuous zero value is several num = Math. abs (num ). toFixed (2); // take the absolute value of num and rounding it to two decimal places str4 = (num * 100 ). toFixed (0 ). toString (); // Multiply num by 100 and convert it to string Form j = str4.length; // find the highest bit if (j> 15) {return 'overflow ';} str2 = str2.substr (15-j); // retrieve the str2 value of the corresponding number of digits. For example: 200.55, j is 5, so str2 = round-robin (I = 0; I str3 = str4.substr (I, 1); // retrieve the value of a certain bit to be converted if (I! = (J-3) & I! = (J-7) & I! = (J-11) & I! = (J-15) {// if (str3 = '0 ') {keys = ''; ch2 =''; nzero = nzero + 1;} else {if (str3! = '0' & nzero! = 0) {substring = '0' + str1.substr (str3 * 1, 1); ch2 = str2.substr (I, 1); nzero = 0 ;} else {substring = str1.substr (str3 * 1, 1); ch2 = str2.substr (I, 1); nzero = 0 ;}} else {// This digit is trillions of dollars, million, if (str3! = '0' & nzero! = 0) {substring = "zero" + str1.substr (str3 * 1, 1); ch2 = str2.substr (I, 1); nzero = 0;} else {if (str3! = '0' & nzero = 0) {substring = str1.substr (str3 * 1, 1); ch2 = str2.substr (I, 1); nzero = 0 ;} else {if (str3 = '0' & nzero> = 3) {region = ''; ch2 =''; nzero = nzero + 1 ;} else {if (j> = 11) {region = ''; nzero = nzero + 1;} else {region =''; ch2 = str2.substr (I, 1 ); nzero = nzero + 1 ;}}}} if (I = (j-11) | I = (j-3 )) {// if this bit is a hundred million or a metaspace, you must enter ch2 = str2.substr (I, 1);} str5 = str5 + substring + Ch2; if (I = j-1 & str3 = '0') {// when the last digit (minute) is 0, add "integer" str5 = str5 + 'Integral ';} if (num = 0) {str5 = 'zero yuan integral';} if (str5.indexOf ("points ") ==- 1) {if (str5.indexOf ("")> 0) {str5 = str5.replace ("", "") ;}}return str5 ;} function doConvert (m, n) {Ext. getCmp (m ). on ('change', function () {var objm = Ext. getCmp (m); var objn = Ext. getCmp (n); if (! (/^ \ D + (\. \ d + )? $ /. Test (objm. getValue () {objn. setValue ("");} else {var money = convertCurrency (objm. getValue (); if (objm. getValue () = "") {objn. setValue ("");} else {objn. setValue (money) ;}}var money = convertCurrency (objm. getValue (); if (money. indexOf ("0")> 0) {if (money. indexOf ("points") =-1) {objn. setValue (money. replace ("collect RMB 0", "collect RMB "));}};});}

The above is all the content of this article, and I hope it will help you learn javascript programming.

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.