Digital currency to Chinese currency

Source: Internet
Author: User

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> digital currency to Chinese currency </title>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">

Function Transform ()
{
 
VaR num = Document. getelementbyid ("num"). value;
For (I = num. Length-1; I> = 0; I --)
{
Num = num. Replace (",", ""); // Replace "," in the text box
Num = num. Replace ("", ""); // Replace the space in the text box
}

Num = num. Replace ("¥", ""); // Replace the possible ¥ characters
If (isnan (Num ))
{
// Verify whether the entered character is a number
Alert ("check whether the entered amount is correct ");
Return;
}

// --- After the character processing is complete, start to convert. The conversion starts with the first and second parts ---//
Part = new string (Num). Split ('.');
Newchar = "";
// Convert before decimal point
For (I = part [0]. Length-1; I> = 0; I --)
{
If (part [0]. length> 10)
{
Alert ("too large to calculate ");
Return "";
}
// If the number of units exceeds, prompt =
Tmpnewchar = ""
VaR perchar = part [0]. charat (I );
Switch (perchar)
{
Case "0 ":
Tmpnewchar = "zero" + tmpnewchar;
Break;
Case "1 ":
Tmpnewchar = "1" + 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:
If (perchar! = 0)
Tmpnewchar = tmpnewchar + "Ten 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 = "zero" + tmpnewchar;
Break;
Case "1 ":
Tmpnewchar = "1" + 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 (" ","");
Newcahr = newchar. Replace ("0 points ","");
If (newchar. charat (newchar. Length-1) = "" | newchar. charat (newchar. Length-1) = "")
Newchar = newchar + "integer ";
Alert (newchar );
}
</SCRIPT>

<Body>
<Form action = "" method = "Post" name = "form1">
Digital currency:
<Input type = "text" name = "num" id = "num"/>
<Input type = "button" name = "btn1" id = "button" value = "convert" onclick = "transform ()"/>
</Form>
</Body>
</Html>

 

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.