在C#中將數字轉換成中文

上篇咱們講了在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

相關文章
相關標籤/搜索