C # convert the numeric amount to the capital amount

Source: Internet
Author: User

 

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;
}
}

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.