1
public class XConvert
2
{
3
public static string ToRMB(Double e)
4
{
5
return ToRMB(System.Convert.ToDecimal(e));
6
}
7
8
public static string ToRMB(Decimal e)
9
{
10
string eString;//数字的格式化字符串
11
string eNum;//单数字
12
int eLen;//格式化字符串长度
13
14
System.Text.StringBuilder rmb=new System.Text.StringBuilder();//人民币大写
15
string yuan;//圆
16
bool seriesZero;//连续0标志
17
bool minus=false;//负数标志
18
19
if (e==0m)
20
{
21
return "零圆整";
22
}
23
if (e<0m)
24
{
25
minus=true;
26
e=System.Math.Abs(e);
27
}
28
if (e>999999999999.99m)
29
{
30
throw new Exception("超过最大范围");
31
}
32
33
eString=e.ToString("0.00");
34
eLen=eString.Length;
35
yuan=(eString.Substring(0,1)=="0"?"":"圆");
36
37
eNum=eString.Substring(eLen-1,1);//分位
38
if (eNum=="0")
39
{
40
rmb.Append("整");
41
seriesZero=true;
42
}
43
else
44
{
45
rmb.Append(stringNum(eNum)+"分");
46
seriesZero=false;
47
}
48
49
eNum=eString.Substring(eLen-2,1);//角位
50
if (eNum=="0")
51
{
52
if (!seriesZero)
53
{
54
if (!(eLen==4&&eString.Substring(0,1)=="0"))
55
{
56
rmb.Insert(0,"零");
57
}
58
}
59
}
60
else
61
{
62
rmb.Insert(0,stringNum(eNum)+"角");
63
seriesZero=false;
64
}
65
66
if (eLen<=7)
67
{
68
rmb.Insert(0,stringNum4(eString.Substring(0,eLen-3))+yuan);
69
}
70
else if (eLen<=11)
71
{
72
rmb.Insert(0,stringNum4(eString.Substring(eLen-7,4))+yuan);
73
rmb.Insert(0,stringNum4(eString.Substring(0,eLen-7))+"万");
74
}
75
else if (eLen<=15)
76
{
77
rmb.Insert(0,stringNum4(eString.Substring(eLen-7,4))+yuan);
78
rmb.Insert(0,stringNum4(eString.Substring(eLen-11,4))+(eString.Substring(eLen-11,4)=="0000"?"":"万"));
79
rmb.Insert(0,stringNum4(eString.Substring(0,eLen-11))+"亿");
80
}
81
82
if (minus) rmb.Insert(0,"负");
83
84
return rmb.ToString();
85
}
86
87
private static string stringNum4(string eNum4)
88
{
89
string eNum;
90
bool seriesZero=false;
91
System.Text.StringBuilder rmb4=new System.Text.StringBuilder();
92
int eLen=eNum4.Length;
93
94
eNum=eNum4.Substring(eLen-1,1);//个位
95
if (eNum=="0")
96
{
97
seriesZero=true;
98
}
99
else
100
{
101
rmb4.Append(stringNum(eNum));
102
}
103
104
if (eLen>=2)//十位
105
{
106
eNum=eNum4.Substring(eLen-2,1);
107
if (eNum=="0")
108
{
109
if (!seriesZero)
110
{
111
rmb4.Insert(0,"零");
112
seriesZero=true;
113
}
114
}
115
else
116
{
117
rmb4.Insert(0,stringNum(eNum)+"拾");
118
seriesZero=false;
119
}
120
}
121
122
if (eLen>=3)//百位
123
{
124
eNum=eNum4.Substring(eLen-3,1);
125
if(eNum=="0")
126
{
127
if (!seriesZero)
128
{
129
rmb4.Insert(0,"零");
130
seriesZero=true;
131
}
132
}
133
else
134
{
135
rmb4.Insert(0,stringNum(eNum)+"佰");
136
seriesZero=false;
137
}
138
}
139
140
if (eLen==4)//千位
141
{
142
eNum=eNum4.Substring(0,1);
143
if(eNum=="0")
144
{
145
if (!seriesZero)
146
{
147
rmb4.Insert(0,"零");
148
seriesZero=true;
149
}
150
}
151
else
152
{
153
rmb4.Insert(0,stringNum(eNum)+"仟");
154
seriesZero=false;
155
}
156
}
157
158
return rmb4.ToString();
159
}
160
161
private static string stringNum(string eNum)
162
{
163
switch (eNum)
164
{
165
case "1":
166
return "壹";
167
case "2":
168
return "贰";
169
case "3":
170
return "叁";
171
case "4":
172
return "肆";
173
case "5":
174
return "伍";
175
case "6":
176
return "陆";
177
case "7":
178
return "柒";
179
case "8":
180
return "捌";
181
case "9":
182
return "玖";
183
default:
184
return "";
185
}
186
}
187
}
不足之处,望朋友们指正。

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187
