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