For the sake of business needs, I wrote a boring method to output Chinese numbers, and the efficiency is barely satisfactory. If you have any better methods, follow up.
1
2 /**/ /// <Summary>
3 /// Chinese count
4 /// </Summary>
5 /// <Param name = "num"> [1, 99999] </Param>
6 /// <Returns> </returns>
7 Public Static String Numtochinesenumstr ( Int Num)
8 {
9 If (Num <= 0 | Num > 99999 )
10 Throw New Argumentexception ( " Num " );
11 String [] Gradechar = New String [] {"","10","Hundred","Thousand","10 thousand"} ;
12 String [] Digitchar = New String [] { " I " , " II " , " 3. " , " Thu " , " V. " , " Sat. " , " VII. " , " 8 " , " 9 " } ;
13 Char Zero = ' Zero ' ;
14
15 Int Length = ( Int ) Math. log10 (Num) + 1 ;
16 Stringbuilder output = New Stringbuilder (length );
17 Int [] Input = New Int [Length];
18 Int Index = - 1 ;
19 While ( ++ Index ! = Length)
20 {
21 Input [Index] = (Num / (Length - Index = 1 ? 1 :( Int ) Math. Pow ( 10 , Length - Index - 1 ))) % 10 ;
22 }
23
24 Bool Needfix = False ;
25 If (Input. Length = 2 && Input [ 0 ] = 1 )
26 Needfix = True ;
27
28 For ( Int Pos = 0 ; POS < Input. length; POS ++ )
29 {
30 If (Input [POS] = 0 )
31 {
32 If (Output [output. Length - 1 ] ! = Zero)
33 Output. append (zero );
34 Continue ;
35 }
36 Else If ( ! (Pos = 0 && Needfix ))
37 {
38Output. append (digitchar [input [POS]-1]);
39}
40 Output. append (gradechar [input. Length - Pos - 1 ]);
41 }
42 If (Output [output. Length - 1 ] = Zero)
43 Output. Remove (output. Length - 1 , 1 );
44 Return Output. tostring ();
45 }
46