1 public static string CmycurD(decimal num)
2 {
3 string strNum = "○一二三四五六七八九"; //0-9所对应的汉字
4 string strUnit = "万千百十亿千百十万千百十 "; //数字位所对应的汉字
5 string strGet = ""; //从原num值中取出的值
6
7 string strTurn = ""; //数字的字符串形式
8 string strOut = ""; //人民币大写金额形式
9 int i; //循环变量
10 int j; //num的值乘以100的字符串长度
11 string ch1 = ""; //数字的汉语读法
12 string ch2 = ""; //数字位的汉字读法
13 int nzero = 0; //用来计算连续的零值是几个
14 int intTemp; //从原num值中取出的值
15
16 //num = Math.Round(Math.Abs(num), 2); //将num取绝对值并四舍五入取2位小数
17 num = Math.Round(num, 0);
18 //str4 = ((long)(num * 100)).ToString(); //将num乘100并转换成字符串形式
19 strTurn = ((long)num).ToString();
20 j = strTurn.Length; //找出最高位
21 if (j > 12) { return "溢出"; }
22 strUnit = strUnit.Substring(13 - j); //取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分
23
24 //循环取出每一位需要转换的值
25 for (i = 0; i < j; i++)
26 {
27 strGet = strTurn.Substring(i, 1); //取出需转换的某一位的值
28 intTemp = Convert.ToInt32(strGet); //转换为数字
29 if (i != (j-1) && i != (j - 5) && i != (j -9))
30 {
31 //当所取位数不为个、万、亿、万亿上的数字时
32 if (strGet == "0")//如果是0
33 {
34 ch1 = "";
35 ch2 = "";
36 nzero = nzero + 1;
37 }
38 else
39 {
40 if (nzero != 0)//如果计数>0
41 {
42 ch1 = "○" + strNum.Substring(intTemp, 1);
43 }
44 else
45 {
46 ch1 = strNum.Substring(intTemp, 1);
47 }
48 ch2 = strUnit.Substring(i, 1);
49 nzero = 0;
50 }
51 }
52 else
53 {
54 //该位是万亿,亿,万,元位等关键位
55 if (strGet != "0" && nzero != 0)
56 {
57 ch1 = "○" + strNum.Substring(intTemp, 1);
58 ch2 = strUnit.Substring(i, 1);
59 nzero = 0;
60 }
61 else
62 {
63 if (strGet != "0" && nzero == 0)
64 {
65 ch1 = strNum.Substring(intTemp, 1);
66 ch2 = strUnit.Substring(i, 1);
67 nzero = 0;
68 }
69 else
70 {
71 if (strGet == "0" && nzero >= 3)
72 {
73 ch1 = "";
74 ch2 = "";
75 nzero = nzero + 1;
76 }
77 else
78 {
79 if (j >= 11)
80 {
81 ch1 = "";
82 nzero = nzero + 1;
83 }
84 else
85 {
86 ch1 = "";
87 ch2 = strUnit.Substring(i, 1);
88 nzero = nzero + 1;
89 }
90 }
91 }
92 }
93 }
94 if (i == (j - 9) || i == (j - 1))
95 {
96 //如果该位是亿位或元位,则必须写上
97 ch2 = strUnit.Substring(i, 1);
98 }
99 strOut = strOut + ch1 + ch2;
106 }
111 strOut = strOut.Substring(0,2).Replace("一十", "十")+strOut.Substring(2);
112 return strOut;
113 }