Effect Chart:
Effect Demo:
<script> Alert (Changermbtoch ("1680760.86")); function Changermbtoch (num) {for (i=num.length-1;i>=0;i--) {num = Num.replace (",", "")//Replace the "," num = num in Tomoney () Replace ("", "")//replaces the space in Tomoney ()} Num = Num.replace ("¥", "")//replace the possible ¥ character if (isNaN (Num)) {//Verify that the entered character is numeric alert ("Please check Lowercase amount is correct "); Return ""; ///---Character processing is completed, the conversion begins, and the transformation is converted using the two parts, respectively---//part = String (Num). Split ("."); Newchar = ""; Convert before decimal for (i=part[0].length-1;i>=0;i--) {if (Part[0].length >) {alert ("too large to compute"); return "";} If the number is more than billion units, the hint 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 if (Num.indexof (".") after the decimal point! =-1) {if (Part[1].length > 2) {alert ("only two digits after the decimal point, the system will automatically truncate"); PART[1] = Part[1].substr (0,2)} for (i=0;i<part[1].length;i++) {Tmpnewchar = "" Perchar = Part[1].charat (i) SWITC H (Perchar) {case "0": tmpnewchar= "0" + Tmpnewchar; Case "1": tmpnewchar= "one" + TmpneWCHAR; break; 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 + "Corner"; if (i==1) Tmpnewchar = Tmpnewchar + "min"; Newchar = Newchar + Tmpnewchar; } if (Newchar.search ("min")!=-1) {Newchar = Newchar.replace ("0", "0"); //Replace all unwanted 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; } </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Core code:
Copy Code code as follows:
function Changermbtoch (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;
}
}
if (Newchar.search ("min")!=-1)
{
Newchar = Newchar.replace ("0 Horns", "0");
}
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;
}