【www.gdgbn.com--计数转换】

asp教程.net 可达千百万亿 人民币小写转大写金额
///


        /// 小写金额转换成大写金额
        ///

        ///
        ///
        ///
        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;
        }
    }

    ///


    /// 大字金额的格式。
    ///

    public enum chnmoneytype
    {
        ///
        /// 支票格式
        ///

        checktype,
        ///
        /// 发票格式
        ///

        invoicetype
    }

 

本文来源:http://www.gdgbn.com/wangyetexiao/29442/