The method for converting a self-written number into a Chinese capital number is not accurate. If you need it, you can refer to it.
Call method: This. literal1.text = method. getchinanumber (this. textbox1.text );
The test results are as follows:
12345.67)
12345.00: million yuan (in case of zero decimal places)
12345: million yuan (no decimals)
10111)
10101)
10001: yuan (in case of zero three digits)
10000: (in case)
Code
Public Static Class Method
{
// Defines an enumeration type: Numbers
Enum Number
{
Zero, one, two, three, Si, Wu, Lu, Yu, Lu
}
// Defines an enumeration type: the unit before the decimal point
Enum Unitprice
{
Circle, pickup, seek, seek, and ten thousand
}
// Defines an enumeration type: the Unit after the decimal point
Enum Unitpricedot
{
Points, Angles
}
/**/ /// <Summary>
/// Obtain the Chinese uppercase digit format
/// </Summary>
/// <Param name = "strnumber"> Number to be converted </Param>
/// <Returns> </returns>
Public Static String Getchinanumber ( String Strnumber)
{
String Integer;
String Decimal;
String Strreturnvalue = "" ;
String [] Strlst = Strnumber. Split ( ' . ' );
If (Strlst. Length = 1 )
{
Strreturnvalue=Conversionnumber (strlst [0]. Tostring (),True);
}
Else
{
Integer = Conversionnumber (strlst [ 0 ]. Tostring (), True );
Decimal = Conversionnumber (strlst [ 1 ]. Tostring (), False );
Strreturnvalue = Integer + Decimal;
}
Return Strreturnvalue;
}
/**/ /// <Summary>
/// Digital Conversion: converts Arabic numerals to uppercase and lowercase Chinese numerals (only supports conversion of numbers accurate to digits)
/// </Summary>
/// <Param name = "strfigure"> Number </Param>
/// <Param name = "blndecimal"> Decimal point: True indicates the number that converts the integer part, and false indicates the number that converts the decimal part. </Param>
/// <Returns> </returns>
Private Static String Conversionnumber ( String Strfigure, Boolean blndecimal)
{
String Show = "" ;
String Strnumber = "" ;
String Strunit = "" ;
String Strtemp = "" ;
Int J = 0 ;
Char [] N = Strfigure. tochararray ();
For ( Int I = 0 ; I < N. length; I ++ )
{
Strnumber = (Number) N [I]. tostring (). toint (). tostring ();
J = N. Length - 1 - I;
If (Blndecimal)
Strunit = (Unitprice) J). tostring ();
Else
Strunit = (Unitpricedot) J). tostring ();
Strtemp = Strnumber + Strunit;
Switch (Strtemp)
{
Case " Zero latency " : Strtemp = " Zero " ; Break ;
Case " Zero latency " : Strtemp = " Zero " ; Break ;
Case " Zero pick " : Strtemp = " Zero " ; Break ;
Case " Zero circle " : Strtemp = "" ; Break ;
Case " Zero Angle " : Strtemp = "" ; Break ;
Case " Zero score " : Strtemp = "" ; Break ;
}
Show + = Strtemp;
}
Show = Show. Replace ( " Zero zero " , " Zero " );
Show = Show. Replace ( " Zero zero " , " Zero " );
If (Show. endswith ( " Zero " ))
Show = Show. Replace ( " Zero " , "" );
Return Show;
}
}