上篇我们讲了在MSSQL中将数字转换成中文,这篇我们讲讲在C#中将数字转换成中文

下篇将讲一下如何将金额转换成中文金额,废话不多说,具体代码如下:

    /// <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(, );
switch (schar)
{
case "":
res = "一";
break;
case "":
res = "二";
break;
case "":
res = "三";
break;
case "":
res = "四";
break;
case "":
res = "五";
break;
case "":
res = "六";
break;
case "":
res = "七";
break;
case "":
res = "八";
break;
case "":
res = "九";
break;
default:
res = "零";
break;
}
if (str.Length > )
{
switch (str.Length)
{
case :
case :
res += "十";
break;
case :
case :
res += "百";
break;
case :
res += "千";
break;
case :
res += "万";
break;
default:
res += "";
break;
}
res += NumberToChinese(int.Parse(str.Substring(, str.Length - )));
}
return res;
}

使用:

Console.WriteLine(NumberToChinese(22));

结果:

二十二

05-11 00:17