asp.net 可達千百萬億 人民幣小寫轉大寫金額

來源:互聯網
上載者:User

asp教程.net 可達千百萬億 人民幣小寫轉大寫金額
/// <summary>
        /// 小寫金額轉換成大寫金額
        /// </summary>
        /// <param name="number"></param>
        /// <param name="turntype"></param>
        /// <returns></returns>
        public static string converttochnmoney(decimal number, chnmoneytype turntype)
        {

            string s_chnnumstring = "零壹貳三肆伍陸柒捌玖";
            //可正確最大金額可以到千萬億元正,有分位為百萬億元或十萬億
            string result = string.empty;
            if (number > 0)
            {
                string s_dxdw = "分角元拾佰仟萬拾佰仟億拾佰仟萬拾佰仟";
                ulong je = (ulong)(number * 100);
                ulong temnum = je;
                int index = 0;
                for (int n = 0; temnum != 0; n++)
                {
                    index = (int)(temnum - temnum / 10 * 10); //取出最後一個數
                    temnum = temnum / 10;
                    result = s_chnnumstring.substring(index, 1) + s_dxdw.substring(n, 1) + result;    //發票格式
                }
                if (turntype == chnmoneytype.checktype)
                {
                    string temresult = string.empty;
                    string temmoney = string.empty;
                    string unit = string.empty;
                    string digitchar = string.empty;
                    string str1 = "零元萬整";
                    string str2 = "零元萬億整";
                    for (int n = result.length - 2; n >= 0; n = n - 2)  //從後面每二個取字串。
                    {
                        temmoney = result.substring(n, 2);
                        unit = temmoney.substring(1, 1);
                        digitchar = temmoney.substring(0, 1);
                        switch (unit)
                        {
                            case "分":
                                if (digitchar == "零")
                                    temmoney = "整";
                                break;
                            case "元":
                            case "萬":
                            case "億":
                                string temdigitchar = temresult.substring(0, 1);
                                if (digitchar == "零")
                                {
                                    if (str1.indexof(temdigitchar) == -1)
                                        temmoney = unit + "零";
                                    else
                                    {
                                        if (temdigitchar == "萬")
                                            temresult = temresult.substring(1);
                                        temmoney = unit;
                                    }
                                }
                                else if (temdigitchar == "萬")
                                    temresult = temresult.substring(1);
                                break;
                            default:
                                if (digitchar == "零")
                                {
                                    if (str2.indexof(temresult.substring(0, 1)) != -1)
                                        temmoney = "";
                                    else
                                        temmoney = "零";
                                }
                                break;
                        }
                        temresult = temmoney + temresult;
                    }
                    result = temresult;
                }
            }
            return result;
        }
    }

    /// <summary>
    /// 大字金額的格式。
    /// </summary>
    public enum chnmoneytype
    {
        /// <summary>
        /// 支票格式
        /// </summary>
        checktype,
        /// <summary>
        /// 發票格式
        /// </summary>
        invoicetype
    }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.