JS realizes the _javascript skill of RMB Capital amount form Conversion

Source: Internet
Author: User

This example for you to share the JS implementation amount to capitalize the relevant code for your reference, the specific content as follows

function convertcurrency (num) {//Convert to RMB capital amount form var str1 = ' 0 Woolu seven ba Nine ';//0-9 the corresponding Chinese character var str2 = ' thousand thousand hundred million thousand hundred to collect thousand thousand hundred cent to collect the element angle divide ';/number Bit of the corresponding Chinese character var str3; Value removed from the original NUM value var STR4; The string form of the number var str5 = '; RMB Capital amount form var i; Cyclic variable var j; num value multiplied by 100 of the string length var ch1; The digital Chinese reading method var CH2; The Chinese character reading method of digit bit var nzero = 0; The 0 value used to calculate a continuous number is num = Math.Abs (num). toFixed (2); The num is absolute and rounded to 2 decimal STR4 = (num *). toFixed (0). toString (); Multiply num by 100 and convert to string form j = str4.length;
  Find the highest bit if (J >) {return ' overflow '; } str2 = Str2.substr (15-j); Remove the str2 value of the corresponding number of digits. such as: 200.55,j for 5 so str2= hundred points//loop out each need to convert the value for (i = 0; I str3 = Str4.substr (i, 1);//Take out the value of a bit that needs to be converted if (I!= (j-3) &A 
        mp;& i!= (j-7) && i!= (j-11) && i!= (j-15)) {//when the number of digits is not yuan, million, billion, trillion, if (Str3 = ' 0 ') {
        CH1 = ';
        CH2 = ';
      Nzero = Nzero + 1;
          else {if (str3!= ' 0 ' && nzero!= 0) {ch1 = ' 0 ' + str1.substr (STR3 * 1, 1); CH2 = str2.SUBSTR (i, 1);
        Nzero = 0;
          else {ch1 = Str1.substr (STR3 * 1, 1);
          CH2 = Str2.substr (i, 1);
        Nzero = 0; }} else {//This bit is a trillion, billion, million, meta bit etc key bit if (Str3!= ' 0 ' && nzero!= 0) {ch1 = "0" + str1.substr (s
        TR3 * 1, 1);
        CH2 = Str2.substr (i, 1);
      Nzero = 0;
          else {if (str3!= ' 0 ' && Nzero = = 0) {ch1 = Str1.substr (STR3 * 1, 1);
          CH2 = Str2.substr (i, 1);
        Nzero = 0;
            else {if (Str3 = = ' 0 ' && nzero >= 3) {ch1 = ';
            CH2 = ';
          Nzero = Nzero + 1;
              else {if (J >=) {ch1 = ';
            Nzero = Nzero + 1;
              else {ch1 = ';
              CH2 = Str2.substr (i, 1);
            Nzero = Nzero + 1; if (i = = (j-11) | | i = = (j-3)) {//If the bit is a billion-bit or meta-bit, you must write CH2 = Str2.sUbstr (i, 1);
    } STR5 = str5 + ch1 + CH2;
    if (i = = j-1 && str3 = = ' 0 ') {//Last (min) is 0 o'clock, plus "whole" STR5 = STR5 + ' whole ';
  } if (num = = 0) {STR5 = ' 0 yuan whole ';
    } if (Str5.indexof ("cent") = = 1) {if (str5.indexof 0) > 0) {STR5 = Str5.replace ("Pick $0", "pick Yuan");
  };
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 ("cent") = = 1) {Objn.setvalue (Money.replace ("pick $0", "Pick Up"))
      ;
  }
    };
}); }

The above is the entire content of this article, I hope to learn JavaScript program to help you.

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.