Convert the amount in lowercase to Chinese Characters in uppercase (JavaScript)

Source: Internet
Author: User

Function arabia_to_chinese (Num ){
For (I = num. Length-1; I> = 0; I --)
{
Num = num. Replace (",", "") // Replace ","
Num = num. Replace ("", "") // Replace the space in tomoney ()
}
Num = num. Replace ("¥", "") // Replace the possible ¥ characters
If (isnan (Num) {// verify whether the entered character is a number
Alert ("check whether the lower-case amount is correct ");
Return;
}
// --- After the character processing is complete, start to convert. The conversion starts with the first and second parts ---//
Part = string (Num). Split (".");
Newchar = "";
// Convert before decimal point
For (I = part [0]. Length-1; I> = 0; I --){
If (part [0]. length> 10) {alert ("the number of digits is too large to be calculated"); Return ";} // if the number of parts exceeds, a prompt is displayed.
Tmpnewchar = ""
Perchar = part [0]. charat (I );
Switch (perchar ){
Case "0": tmpnewchar = "0" + tmpnewchar; break;
Case "1": tmpnewchar = "" + tmpnewchar; break;
Case "2": tmpnewchar = "" + tmpnewchar; break;
Case "3": tmpnewchar = "" + tmpnewchar; break;
Case "4": tmpnewchar = "Si" + tmpnewchar; break;
Case "5": tmpnewchar = "Wu" + tmpnewchar; break;
Case "6": tmpnewchar = "" + tmpnewchar; break;
Case "7": tmpnewchar = "bytes" + tmpnewchar; break;
Case "8": tmpnewchar = "bytes" + tmpnewchar; break;
Case "9": tmpnewchar = "bytes" + tmpnewchar; break;
}
Switch (part [0]. length-i-1 ){
Case 0: tmpnewchar = tmpnewchar + "Yuan"; break;
Case 1: If (perchar! = 0) tmpnewchar = tmpnewchar + "pick up"; break;
Case 2: If (perchar! = 0) tmpnewchar = tmpnewchar + "bytes"; break;
Case 3: If (perchar! = 0) tmpnewchar = tmpnewchar + "bytes"; break;
Case 4: tmpnewchar = tmpnewchar + "Thousand"; break;
Case 5: If (perchar! = 0) tmpnewchar = tmpnewchar + "pick up"; break;
Case 6: If (perchar! = 0) tmpnewchar = tmpnewchar + "bytes"; break;
Case 7: If (perchar! = 0) tmpnewchar = tmpnewchar + "bytes"; break;
Case 8: tmpnewchar = tmpnewchar + ""; break;
Case 9: tmpnewchar = tmpnewchar + "pick up"; break;
}
Newchar = tmpnewchar + newchar;
}
// Convert the decimal point
If (Num. indexof (".")! =-1 ){
If (part [1]. length> 2 ){
Alert ("Only two digits can be retained after the decimal point, and the system will automatically cut the segment ");
Part [1] = part [1]. substr (0, 2)
}
For (I = 0; I <part [1]. length; I ++ ){
Tmpnewchar = ""
Perchar = part [1]. charat (I)
Switch (perchar ){
Case "0": tmpnewchar = "0" + tmpnewchar; break;
Case "1": tmpnewchar = "" + tmpnewchar; break;
Case "2": tmpnewchar = "" + tmpnewchar; break;
Case "3": tmpnewchar = "" + tmpnewchar; break;
Case "4": tmpnewchar = "Si" + tmpnewchar; break;
Case "5": tmpnewchar = "Wu" + tmpnewchar; break;
Case "6": tmpnewchar = "" + tmpnewchar; break;
Case "7": tmpnewchar = "bytes" + tmpnewchar; break;
Case "8": tmpnewchar = "bytes" + tmpnewchar; break;
Case "9": tmpnewchar = "bytes" + tmpnewchar; break;
}
If (I = 0) tmpnewchar = tmpnewchar + "";
If (I = 1) tmpnewchar = tmpnewchar + "points ";
Newchar = newchar + tmpnewchar;
}
}
// Replace all useless Chinese Characters
While (newchar. Search ("0 ")! =-1)
Newchar = newchar. Replace ("zero", "zero ");
Newchar = newchar. Replace ("0 billion ");
Newchar = newchar. Replace ("hundreds of millions", "hundreds of millions ");
Newchar = newchar. Replace ("0 thousand ");
Newchar = newchar. Replace ("Zero yuan", "Yuan ");
Newchar = newchar. Replace (" ","");
Newchar = newchar. Replace ("0 ","");

If (newchar. charat (newchar. Length-1) = "" | newchar. charat (newchar. Length-1) = "")
Newchar = newchar + "integer"
Return newchar;
}

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.