Some Report programs often need to print the capital amount of RMB, so they write a tool for converting the RMB from lowercase to uppercase within 9 digits.
The Code is as follows:
Using system;
Using system. text;
Namespace rmblowertoupper
{
/// <Summary>
/// Summary of class1.
/// </Summary>
Class ltou
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[Stathread]
Static void main (string [] ARGs)
{
// If (ARGs. length! = 1)
//{
// Console. writeline ("error number! ");
// Return;
//}
String number = NULL;
Do
{
Console. writeline ("Please input a number :");
Stringbuilder sb = new stringbuilder ();
Number = console. Readline ();
String [] DIV = number. Split ('.');
If (Div. length! = 2 | Div [1]. length! = 2)
{
Console. writeline ("error number! ");
Return;
}
// Foreach (string N in Div)
//{
// Console. writeline (N );
//}
# Region -------- process the integer part -------------
Char [] bit = div [0]. tochararray ();
// Convert to uppercase
For (INT I = 0; I <bit. length; I ++)
{
Switch (bit [I])
{
Case '1 ':
SB. append ("1 ");
Break;
Case '2 ':
SB. append ("II ");
Break;
Case '3 ':
SB. append ("3 ");
Break;
Case '4 ':
SB. append ("Si ");
Break;
Case '5 ':
SB. append ("Wu ");
Break;
Case '6 ':
SB. append (" ");
Break;
Case '7 ':
SB. append ("success ");
Break;
Case '8 ':
SB. append ("success ");
Break;
Case '9 ':
SB. append ("success ");
Break;
// Handle situations such as 10000.00, 10020.00, and 1002000.00
Case '0 ':
If (I + 1) <bit. Length & bit [I + 1] = '0 ')
{
SB. append ("");
}
Else if (I = bit. Length-1 | bit. Length-I = 5 | bit. Length-I = 9)
{
SB. append ("");
}
Else
{
SB. append ("0 ");
}
Break;
}
// Insert the corresponding unit
Switch (bit. Length-I)
{
Case 2:
If (bit [I] = '0 ')
{
SB. append ("");
}
Else
{
SB. append ("pick ");
}
Break;
Case 3:
If (bit [I] = '0 ')
{
SB. append ("");
}
Else
{
SB. append ("Hundred ");
}
Break;
Case 4:
If (bit [I] = '0 ')
{
SB. append ("");
}
Else
{
SB. append ("success ");
}
Break;
Case 5:
// If (bit [I] = '0 ')
//{
// Sb. append ("");
//}
// Else
//{
SB. append ("Ten Thousand ");
//}
Break;
Case 6:
If (bit [I] = '0 ')
{
SB. append ("");
}
Else
{
SB. append ("pick ");
}
Break;
Case 7:
If (bit [I] = '0 ')
{
SB. append ("");
}
Else
{
SB. append ("Hundred ");
}
Break;
Case 8:
If (bit [I] = '0 ')
{
SB. append ("");
}
Else
{
SB. append ("success ");
}
Break;
}
}
SB. append ("round ");
# Endregion
# Region ---------- process fractional parts -----------
Char [] Point = div [1]. tochararray ();
For (Int J = 0; j <point. length; j ++)
{
Switch (point [J])
{
Case '1 ':
SB. append ("1 ");
Break;
Case '2 ':
SB. append ("II ");
Break;
Case '3 ':
SB. append ("3 ");
Break;
Case '4 ':
SB. append ("Si ");
Break;
Case '5 ':
SB. append ("Wu ");
Break;
Case '6 ':
SB. append (" ");
Break;
Case '7 ':
SB. append ("success ");
Break;
Case '8 ':
SB. append ("success ");
Break;
Case '9 ':
SB. append ("success ");
Break;
Case '0 ':
If (J + 1) <point. Length & point [J + 1] = '0 ')
{
SB. append ("");
}
Else if (j = point. Length-1)
{
SB. append ("");
}
Else
{
SB. append ("0 ");
}
Break;
}
Switch (point. Length-j)
{
Case 2:
If (point [J] = '0 ')
{
SB. append ("");
}
Else
{
SB. append (" ");
}
Break;
Case 1:
If (point [J] = '0 ')
{
SB. append ("");
}
Else
{
SB. append ("points ");
}
Break;
}
}
# Endregion
String u = sb. tostring ();
Console. writeline (U );
} While (number. toupper ()! = "Exit ");
}
}
}
The test interface is as follows: