上篇咱們講了在MSSQL中將數字轉換成中文,這篇咱們講講在C#中將數字轉換成中文spa
下篇將講一下如何將金額轉換成中文金額,廢話很少說,具體代碼以下:code
/// <summary> /// 數字轉中文 /// </summary> /// <param name="number">eg: 22</param> /// <returns></returns> public string NumberToChinese(int number) { string res = string.Empty; string str = number.ToString(); string schar = str.Substring(0, 1); switch (schar) { case "1": res = "一"; break; case "2": res = "二"; break; case "3": res = "三"; break; case "4": res = "四"; break; case "5": res = "五"; break; case "6": res = "六"; break; case "7": res = "七"; break; case "8": res = "八"; break; case "9": res = "九"; break; default: res = "零"; break; } if (str.Length > 1) { switch (str.Length) { case 2: case 6: res += "十"; break; case 3: case 7: res += "百"; break; case 4: res += "千"; break; case 5: res += "萬"; break; default: res += ""; break; } res += NumberToChinese(int.Parse(str.Substring(1, str.Length - 1))); } return res; }
使用:blog
Console.WriteLine(NumberToChinese(22));
結果:string
二十二it