Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Text;
Namespace Common
{
<summary>
Convert RMB size amount.
</summary>
public class RMB
{
<summary>
Convert RMB size Amount
</summary>
<param name= "num" > Amount </param>
<returns> Return Capital Form </returns>
public static string Cmycurd (decimal num)
{
String str1 = "0 A three Woolu qi Ba Nine"; 0-9 of the corresponding Chinese characters
String str2 = "thousand thousand hundred million thousand hundred to collect thousand thousand hundred cent to collect the element angle"; The Chinese character corresponding to the digit digit
String str3 = ""; Value removed from the original NUM value
String STR4 = ""; The string form of a number
String STR5 = ""; RMB Capital Amount Form
int i; Loop variable
Int J; The value of num multiplied by the string length of 100
String ch1 = ""; The Chinese reading method of numerals
String CH2 = ""; Chinese character reading method of digit digit
int Nzero = 0; Used to calculate a continuous 0 value is a few
int temp; Value removed from the original NUM value
num = Math.Round (math.abs (num), 2); Take num to absolute value and round up 2 decimal places
STR4 = ((long) (NUM * 100)). ToString (); Multiply num by 100 and convert to string form
j = Str4. Length; Find the highest position
if (J >) {return "overflow";}
STR2 = str2. Substring (15-J); Remove the str2 value of the corresponding number of digits. such as: 200.55,j is 5 so str2= hundred cents points
Loop out every bit of value that needs to be converted
for (i = 0; i < J; i++)
{
STR3 = Str4. Substring (i, 1); Remove the value of a bit that needs to be converted
temp = Convert.ToInt32 (STR3); Convert to Number
if (I!= (j-3) && i!= (j-7) && i!= (j-11) && i!= (j-15))
{
When the number of digits is not the number of dollars, million, billions, trillion,
if (STR3 = = "0")
{
CH1 = "";
CH2 = "";
Nzero = Nzero + 1;
}
Else
{
if (Str3!= "0" && nzero!= 0)
{
CH1 = "0" + str1. Substring (TEMP * 1, 1);
CH2 = str2. Substring (i, 1);
Nzero = 0;
}
Else
{
CH1 = str1. Substring (TEMP * 1, 1);
CH2 = str2. Substring (i, 1);
Nzero = 0;
}
}
}
Else
{
The bit is a trillion, billion, million, bits and so the key bit
if (Str3!= "0" && nzero!= 0)
{
CH1 = "0" + str1. Substring (TEMP * 1, 1);
CH2 = str2. Substring (i, 1);
Nzero = 0;
}
Else
{
if (Str3!= "0" && Nzero = = 0)
{
CH1 = str1. Substring (TEMP * 1, 1);
CH2 = str2. Substring (i, 1);
Nzero = 0;
}
Else
{
if (STR3 = = "0" && Nzero >= 3)
{
CH1 = "";
CH2 = "";
Nzero = Nzero + 1;
}
Else
{
if (J >= 11)
{
CH1 = "";
Nzero = Nzero + 1;
}
Else
{
CH1 = "";
CH2 = str2. Substring (i, 1);
Nzero = Nzero + 1;
}
}
}
}
}
if (i = = (j-11) | | i = = (j-3))
{
If the bit is billion-bit or meta, you must write
CH2 = str2. Substring (i, 1);
}
STR5 = STR5 + ch1 + CH2;
if (i = = j-1 && STR3 = = "0")
{
The last one (points) is 0 o'clock, plus "whole"
STR5 = Str5 + ' whole ';
}
}
if (num = 0)
{
STR5 = "0 yuan whole";
}
return STR5;
}
<summary>
Converts RMB size amount (an overload, converts a string to a number before calling Cmycurd)
</summary>
<param name= "num" > The amount entered by the user, the string form is not converted to decimal</param>
<returns></returns>
public static string Cmycurd (String numstr)
{
Try
{
Decimal num = Convert.todecimal (NUMSTR);
return Cmycurd (num);
}
Catch
{
Return "non-digital form! ";
}
}
}
}