JS function to convert amount numbers to uppercase characters

Source: Internet
Author: User

1 //function to convert amount numbers to uppercase characters2 functionconvertcurrency (Money) {3     //number of Chinese characters4     varCnnums =NewArray (' 0 ', ' one ', ' II ', ' three ', ' establishments ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU ');5     //basic Unit6     varCnintradice =NewArray (', ' Pick ', ' bai ', ' thousand ');7     //corresponding integer part expansion unit8     varCnintunits =NewArray (' ', ' million ', ' billion ', ' Mega ');9     //corresponds to fractional part unitsTen     varCndecunits =NewArray (' angle ', ' minute ', ' Milli ', ' CL '); One     //character followed by integer amount A     varCninteger = ' whole '; -     //units After completion of the integer type -     varCnintlast = ' Yuan '; the     //maximum number of processed -     varMaxnum = 999999999999999.9999; -     //Amount Integer Part -     varIntegernum; +     //amount of small part -     varDecimalnum; +     //Chinese amount string for output A     varChinesestr = ' '; at     //array used after separating amount, pre-defined -     varparts; -     if(Money = = ") { -         return‘‘; -     } -Money =parsefloat (money); in     if(Money >=maxnum) { -         //maximum processing number exceeded to         return‘‘; +     } -     if(Money = = 0) { theChinesestr = Cnnums[0] + cnintlast +Cninteger; *         returnChinesestr; $     }Panax Notoginseng     //Convert to String -Money =money.tostring (); the     if(Money.indexof ('. ') = =-1) { +Integernum =Money ; ADecimalnum = ' '; the     } +     Else { -Parts = Money.split ('. ')); $Integernum = Parts[0]; $Decimalnum = Parts[1].substr (0, 4); -     } -     //get integral partial conversions the     if(parseint (Integernum, ten) > 0) { -         varZerocount = 0;Wuyi         varIntlen =integernum.length; the          for(vari = 0; i < Intlen; i++) { -             varn = integernum.substr (i, 1); Wu             varp = intlen-i-1; -             varQ = P/4; About             varm = p% 4; $             if(n = = ' 0 ') { -zerocount++; -             } -             Else { A                 if(Zerocount > 0) { +Chinesestr + = Cnnums[0]; the                 } -                 //return to zero $Zerocount = 0; theChinesestr + = Cnnums[parseint (n)] +Cnintradice[m]; the             } the             if(M = = 0 && Zerocount < 4) { theChinesestr + =Cnintunits[q]; -             } in         } theChinesestr + =Cnintlast; the     } About     //number of decimal parts the     if(Decimalnum! = ") { the         varDeclen =decimalnum.length; the          for(vari = 0; i < Declen; i++) { +             varn = decimalnum.substr (i, 1); -             if(n! = ' 0 ') { theChinesestr + = Cnnums[number (n)] +Cndecunits[i];Bayi             } the         } the     } -     if(Chinesestr = = "") { -Chinesestr + = Cnnums[0] + cnintlast +Cninteger; the     } the     Else if(Decimalnum = = "") { theChinesestr + =Cninteger; the     } -     returnChinesestr; the}

JS function to convert amount numbers to uppercase characters

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.