CSharp-将数字转换为中文描述

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

将数字转换为英文描述不考虑负数情况,将数字转换为中文描述。比如24={二十四}102={一百零二}1005={一千零五}1012={一千零一十二}.程序源代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Runtime.InteropServices;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.IO;namespaceRemainerMaths{classProgram{//将数字转换为中文描述//如:24二十四102:一百零二//1005:一千零五1012:一千零一十二staticvoidMain(string[]args){int[]arr={0,1,2,11,15,80,99,100,106,110,118,185,199,900,999,1000,1002,1011,4025,6101,9999,10000,30005,110025,860123,8888888,99999999,100000000,1200000008,1400000012,1600000110,1700102345,1824765421};for(inti=0;iarr.Length;i++)//右对齐,长度凑满10位{Console.WriteLine({0,10}={{{1}}},arr[i],NumberToChineseString(arr[i]));}Console.ReadLine();}///summary///把数字转换为中文描述///如132对应一百三十二///10003对应一万零三////summary///paramname=number/param///returns/returnsstaticstringNumberToChineseString(intnumber){if(number0)//负数暂不考虑return;if(number20)//0到之间的数{switch(number){case0:return零;case1:return一;case2:return二;case3:return三;case4:return四;case5:return五;case6:return六;case7:return七;case8:return八;case9:return九;case10:return十;case11:return十一;case12:return十二;case13:return十三;case14:return十四;case15:return十五;case16:return十六;case17:return十七;case18:return十八;case19:return十九;default:return;}}if(number100)//20到之间的数{if(number%10==0)//20,30,40...90这些数{returnstring.Format({0}十,NumberToChineseString(number/10));}else//21,58,99这些数{returnstring.Format({0}十{1},NumberToChineseString(number/10),NumberToChineseString(number%10));}}if(number1000)//100到之间的数{if(number%100==0){returnstring.Format({0}百,NumberToChineseString(number/100));}else{//如果十位是,返回零,而不是零十。个位是,返回空returnstring.Format({0}百{1}{2},NumberToChineseString(number/100),NumberToChineseString(number%100/10)+(number%100/10==0?:十),number%10==0?:NumberToChineseString(number%10));}}if(number10000)//1000到之间的数{if(number%1000==0){returnstring.Format({0}千,NumberToChineseString(number/1000));}else{//如果十位是,返回零,而不是零十。个位是,返回空if(number%100010){returnstring.Format({0}千零{1},NumberToChineseString(number/1000),NumberToChineseString(number%10));}elseif(number%1000100){returnstring.Format({0}千零{1}十{2},NumberToChineseString(number/1000),NumberToChineseString(number%1000/10),number%10==0?:NumberToChineseString(number%10));}else{returnstring.Format({0}千{1},NumberToChineseString(number/1000),NumberToChineseString(number%1000));}}}if(number100000000)//一万到9999之间{if(number%10000==0){returnstring.Format({0}万,NumberToChineseString(number/10000));}else{if(number%1000010){returnstring.Format({0}万零{1},NumberToChineseString(number/10000),NumberToChineseString(number%10));}elseif(number%10000100){returnstring.Format({0}万零{1}十{2},NumberToChineseString(number/10000),NumberToChineseString(number%10000/10),number%10==0?:NumberToChineseString(number%10));}elseif(number%100001000){returnstring.Format({0}万零{1},NumberToChineseString(number/10000),NumberToChineseString(number%10000));}else{returnstring.Format({0}万{1},NumberToChineseString(number/10000),NumberToChineseString(number%10000));}}}if(number=int.MaxValue)//一亿以上{if(number%100000000==0){returnstring.Format({0}亿,NumberToChineseString(number/100000000));}else{if(number%10000000010){returnstring.Format({0}亿零{1},NumberToChineseString(number/100000000),NumberToChineseString(number%10));}elseif(number%100000000100){returnstring.Format({0}亿零{1}十{2},NumberToChineseString(number/100000000),NumberToChineseString(number%100000000/10),number%10==0?:NumberToChineseString(number%10));}elseif(number%1000000001000){returnstring.Format({0}亿零{1},NumberToChineseString(number/100000000),NumberToChineseString(number%100000000));}else{returnstring.Format({0}亿{1},NumberToChineseString(number/100000000),NumberToChineseString(number%100000000));}}}return;}}}程序运行结果如图:

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功