最近在用这个博客,感觉博客园不错,以前用的是新浪的,感觉这个更好,所以好多东西现在转到这边来了。
下面是一个数字转人民币大写的类,不啰嗦了,下面是代码:
1 /// <summary>
2 /// 把数字金额转换成人民币大写
3 /// </summary>
4 /// <param name="DataInput">要转换的数字金额</param>
5 /// <param name="DisplayZero">是否显示全部零</param>
6 /// <returns></returns>
7 public string DaXieMoney(double DataInput,bool DisplayZero)
8 {
9 //将数值转换为大写金额
10 //18个单位
11 int overOp;
12 string []StrScale ={"分","角","元","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","兆","拾","佰","仟"};
13 //10个数字
14 string []StrNumber ={ "零","壹","贰", "叁","肆","伍","陆","柒","捌","玖"};
15 string Temp=DataInput.ToString();
16 // 当小数点不存在或只有一位小数时的处理
17 if(Temp.IndexOf(".")==-1)
18 overOp=2;
19 else
20 overOp=Temp.IndexOf(".")+3-Temp.Length;
21 // 如果小数位超出三位小数则不处理
22 if(overOp<0)
23 return "只能精确到分.";
24 //去掉小数点
25 string StrTemp=Temp.Replace(".","");
26 string StrResult = "";
27 for (int i = StrTemp.Length; i > 0; i--)
28 {
29 StrResult += StrNumber[Convert.ToInt16(StrTemp[StrTemp.Length-i].ToString())];
30 StrResult += StrScale[i-1+overOp];
31 }
32 // 当要求显示零时可以直接返回字符串。
33 if(DisplayZero==true)
34 return StrResult;
35 // 去掉多余的零,以便符合语法规则。
36 StrResult=StrResult.Replace("零仟","零");
37 StrResult=StrResult.Replace("零佰","零");
38 StrResult=StrResult.Replace("零拾","零");
39 StrResult=StrResult.Replace("零零零零元","元");
40 StrResult=StrResult.Replace("零零零零万","");
41 StrResult=StrResult.Replace("零零零零亿","");
42 StrResult=StrResult.Replace("零零零零兆","");
43 StrResult=StrResult.Replace("零零零","零");
44 StrResult=StrResult.Replace("零零","零");
45 StrResult=StrResult.Replace("零元","元");
46 StrResult=StrResult.Replace("零万","万");
47 StrResult=StrResult.Replace("零亿","亿");
48 StrResult=StrResult.Replace("零兆","兆");
49 return StrResult;
50 }
51