资源描述:
《c#数字转换成大写汉字》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C#数字转换成大写汉字C#数字转换成大写汉字程序usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceConsoleApplication1{publicclassProgram{staticvoidMain(string[]args){System.Console.Write("金额:");strings=System.Console.ReadLine();doublem;try{m=double.Parse(s);Moneymoney=newMoney(m);Console.WriteLine(mon
2、ey.Convert());}catch(FormatExceptionex){System.Console.WriteLine(ex.Message);}}}publicclassMoney{//////要转换的数字///privatedoublej;/////////privatestring[]NumChineseCharacter=newstring[]{"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};publicMoney(doublem){this.j=m;}///
3、ummary>///判断输入的数字是否大于double类型///privateboolIsNumber{get{if(j>double.MaxValue
4、
5、j<=0)returnfalse;elsereturntrue;}}//////数字转换成大写汉字主函数//////返回转换后的大写汉字publicstringConvert(){stringbb="";if(IsNumber){stringstr=j.ToString();string[]Num=str.Split('.');if(Num.
6、Length==1){bb=NumberString(Num[0])+"元整";bb=bb.Replace("零零","零");}else{bb=NumberString(Num[0])+"元";bb+=FloatString(Num[1]);bb=bb.Replace("零零","零");}}else{thrownewFormatException("你输入的数字格式不正确或不是数字!");}returnbb;}//////小数位转换只支持两位的小数//////转换的小数///小数转
7、换成汉字privatestringFloatString(stringNum){stringcc="";if(Num.Length>2){thrownewFormatException("小数位数过多.");}else{stringbb=ConvertString(Num);intlen=bb.IndexOf("零");if(len!=0){bb=bb.Replace("零","");if(bb.Length==1){cc=bb.Substring(0,1)+"角整";}else{cc=bb.Substring(0,1)+"角";cc+=bb.Substring(1,1
8、)+"分";}}elsecc=bb+"分";}returncc;}//////判断数字位数以进行拆分转换//////要进行拆分的数字///转换成的汉字privatestringNumberString(stringNum){stringbb="";if(Num.Length<=4){bb=Convert4(Num);}elseif(Num.Length>4&&Num.Length<=8){bb=Convert4(Num.Substring(0,Num.Length-
9、4))+"万";bb+=Convert4(Num.Substring(Num.Length-4,4));}elseif(Num.Length>8&&Num.Length<=12){bb=Convert4(Num.Substring(0,Num.Length-8))+"亿";if(Convert4(Num.Substring(Num.Length-8,4))=="")if(Convert4(Num.Substring(Nu