Native JavaScript implements amount capitalization conversion function

Source: Internet
Author: User

functiontransform (tranvalue) {Try {    vari = 1; varDW2 =NewArray ("", "Million", "billion");//Large Units    varDW1 =NewArray ("Pick", "Bai", "thousand");//Small Units    varDW =NewArray ("0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "JIU");//integer part with    //The following is lowercase converted to uppercase in the total uppercase text box    //separating integers from decimals    varSource =splits (Tranvalue); varnum = source[0]; varDig = source[1]; //Convert integer part    varK1 = 0;//count Small units    varK2 = 0;//count Large units    varsum = 0; varstr = ""; varlen = source[0].length;//the length of an integer     for(i = 1; I <= Len; i++) {      varn = Source[0].charat (len-i);//get a number on a single digit      varbn = 0; if(len-i-1 >= 0) {bn= Source[0].charat (Len-i-1);//get a number on a single digit before the first one} sum= Sum +Number (n); if(Sum! = 0) {str= Dw[number (n)].concat (str);//get the uppercase number corresponding to the number and insert it in front of the STR string        if(n = = ' 0 ') sum = 0; }      if(len-i-1 >= 0) {//within the range of numbers        if(K1! = 3) {//Add small units          if(Bn! = 0) {str=Dw1[k1].concat (str); } K1++; } Else{//do not add small units, increase unitsK1 = 0; vartemp = Str.charat (0); if(temp = = "Million" | | temp = = "million")//If there is no number in front of the large unitstr = STR.SUBSTR (1, str.length-1); STR=Dw2[k2].concat (str); Sum= 0; }      }      if(K1 = = 3)//small units to thousands of large units into a{K2++; }    }    //Converting a decimal part    varStrdig = ""; if(Dig! = "") {      varn = Dig.charat (0); if(n! = 0) {Strdig+ = Dw[number (n)] + "angle";//Plus numbers      }      varn = Dig.charat (1); if(n! = 0) {Strdig+ = Dw[number (n)] + "min";//Plus numbers}} str+ = "Yuan" +Strdig; } Catch(e) {return"0 Yuan"; }  returnstr;}//splitting integers and decimalsfunctionSplits (tranvalue) {varValue =NewArray (' ', ' '); Temp= Tranvalue.split (".");  for(vari = 0; i < temp.length; i++) {Value[i]=Temp[i]; }  returnvalue;}

Native JavaScript implements amount capitalization conversion function

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.