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