Js| Capital | amount | lowercase
More Classic Code!
Keep 2 decimal digits, otherwise there will be an error!
Integer amount must be in format: 12345.00 Otherwise there will be an error!
If combined with ASP's formatcurrency, can solve this problem!
<script language= "JavaScript" type= "Text/javascript" >
function Arabia_to_chinese (Num) {
for (i=num.length-1;i>=0;i--)
{
Num = Num.replace (",", "")//Replace the "," in Tomoney ()
Num = Num.replace ("", "")//Replace the space in Tomoney ()
}
Num = Num.replace ("¥", "")//replace the possible ¥ characters
if (isNaN (Num)) {//Verify that the character entered is a number
Alert ("Please check the lowercase amount is correct");
Return
}
---character processing finished, start conversion, conversion using the two parts of the conversion---//
Part = String (Num). Split (".");
Newchar = "";
Convert before a decimal point
for (i=part[0].length-1;i>=0;i--) {
if (Part[0].length >) {alert ("too large to compute"); return "";} If the number of more than million units, prompted
Tmpnewchar = ""
Perchar = Part[0].charat (i);
Switch (Perchar) {
Case "0": tmpnewchar= "0" + Tmpnewchar;
Case "1": tmpnewchar= "one" + Tmpnewchar;
Case "2": tmpnewchar= "II" + Tmpnewchar;
Case "3": tmpnewchar= "three" + Tmpnewchar;
Case "4": tmpnewchar= "Restaurant" + Tmpnewchar;
Case "5": Tmpnewchar= "WU" + tmpnewchar;
Case "6": Tmpnewchar= "Lu" + tmpnewchar;
Case "7": tmpnewchar= "qi" + Tmpnewchar;
Case "8": tmpnewchar= "ba" + Tmpnewchar;
Case "9": tmpnewchar= "nine" + Tmpnewchar;
}
Switch (part[0].length-i-1) {
Case 0:tmpnewchar = Tmpnewchar + "Yuan";
Case 1:if (perchar!=0) tmpnewchar= Tmpnewchar + "pick up";
Case 2:if (perchar!=0) tmpnewchar= Tmpnewchar + "Bai";
Case 3:if (perchar!=0) tmpnewchar= Tmpnewchar + "thousand";
Case 4:tmpnewchar= Tmpnewchar + "million";
Case 5:if (perchar!=0) tmpnewchar= Tmpnewchar + "pick up";
Case 6:if (perchar!=0) tmpnewchar= Tmpnewchar + "Bai";
Case 7:if (perchar!=0) tmpnewchar= Tmpnewchar + "thousand";
Case 8:tmpnewchar= Tmpnewchar + "billion";
Case 9:tmpnewchar= Tmpnewchar + "pick up";
}
Newchar = Tmpnewchar + Newchar;
}
Convert after a decimal point
if (Num.indexof (".")! =-1) {
if (Part[1].length > 2) {
Alert ("Only two digits can be retained after the decimal point, the system will automatically intercept");
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;
Case "1": tmpnewchar= "one" + Tmpnewchar;
Case "2": tmpnewchar= "II" + Tmpnewchar;
Case "3": tmpnewchar= "three" + Tmpnewchar;
Case "4": tmpnewchar= "Restaurant" + Tmpnewchar;
Case "5": Tmpnewchar= "WU" + tmpnewchar;
Case "6": Tmpnewchar= "Lu" + tmpnewchar;
Case "7": tmpnewchar= "qi" + Tmpnewchar;
Case "8": tmpnewchar= "ba" + Tmpnewchar;
Case "9": tmpnewchar= "nine" + Tmpnewchar;
}
if (i==0) Tmpnewchar =tmpnewchar + "angle";
if (i==1) Tmpnewchar = Tmpnewchar + "min";
Newchar = Newchar + Tmpnewchar;
}
// }
Replace all useless characters
while (Newchar.search ("00")!=-1)
Newchar = Newchar.replace ("00", "0");
Newchar = Newchar.replace ("0", "billion");
Newchar = Newchar.replace ("Billions", "billion");
Newchar = Newchar.replace ("0", "million");
Newchar = Newchar.replace ("0 yuan", "Yuan");
Newchar = Newchar.replace ("0 Horns", "");
Newchar = Newchar.replace ("0 points", "");
if (Newchar.charat (newchar.length-1) = = "Yuan" | | | Newchar.charat (newchar.length-1) = = "Corner")
Newchar = newchar+ "whole"
return Newchar;
}
Alert (Arabia_to_chinese (22.6));
</script>
<script language= "VBScript" type= "Text/vbscript" >
function Z ()
Document.all.form1.j2.value=arabia_to_chinese (Document.all.form1.j1.value)
End Function
</script>
<form name= "Form1" method= "Post" action= "" >
<input type= "text" name= "J1" >
<input type= "text" name= "J2" >
</form>