JS converts a number into an uppercase renminbi expression

Source: Internet
Author: User

functionChangenummoneytochinese (Money) {varCnnums =NewArray ("0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "JIU");//number of Chinese characters    varCnintradice =NewArray ("", "Pick", "Bai", "thousand");//basic Unit    varCnintunits =NewArray ("", "Million", "billion", "Mega");//corresponding integer part expansion unit    varCndecunits =NewArray ("angle", "minute", "MM", "CL");//corresponds to fractional part units    varCninteger = "whole";//character followed by integer amount    varCnintlast = "Yuan";//units After completion of the integer type    varMaxnum = 999999999999999.9999;//maximum number of processed    varIntegernum;//Amount Integer Part    varDecimalnum;//amount of small part    varChinesestr = "";//Chinese amount string for output    varParts//array used after separating amount, pre-defined    if(Money = = "")) {        return""; } Money=parsefloat (Money); if(Money >=maxnum) {Alert (' exceeds maximum processing number '); return""; }    if(Money = = 0) {Chinesestr= Cnnums[0] + cnintlast +Cninteger; returnChinesestr; } Money= Money.tostring ();//Convert to String    if(Money.indexof (".") = =-1) {Integernum=Money ; Decimalnum= ' '; } Else{Parts= Money.split ("."); Integernum= Parts[0]; Decimalnum= Parts[1].substr (0, 4); }    if(parseint (Integernum, ten) > 0) {//get integral partial conversions        varZerocount = 0; varIntlen =integernum.length;  for(vari = 0; i < Intlen; i++) {            varn = integernum.substr (i, 1); varp = intlen-i-1; varQ = P/4; varm = p% 4; if(n = = "0") {Zerocount++; } Else {                if(Zerocount > 0) {Chinesestr+ = Cnnums[0]; } Zerocount= 0;//return to zeroChinesestr + = Cnnums[parseint (n)] +Cnintradice[m]; }            if(M = = 0 && Zerocount < 4) {Chinesestr+=Cnintunits[q]; }} chinesestr+=Cnintlast; //integral part processing complete    }    if(Decimalnum! = ") {//number of decimal parts        varDeclen =decimalnum.length;  for(vari = 0; i < Declen; i++) {            varn = decimalnum.substr (i, 1); if(n! = ' 0 ') {Chinesestr+ = Cnnums[number (n)] +Cndecunits[i]; }        }    }    if(Chinesestr = = "") {Chinesestr+ = Cnnums[0] + cnintlast +Cninteger; } Else if(Decimalnum = = "") {Chinesestr+=Cninteger; }    returnchinesestr;}

JS converts a number into an uppercase renminbi expression

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.