在C#中将数字转换成中文

上篇我们讲了在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(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;
    }

使用:

Console.WriteLine(NumberToChinese(22));

结果:

二十二

posted @ 2015-06-10 21:55  ZuQing  阅读(19071)  评论(6编辑  收藏  举报