我的程序我做主
~天~注~定~

在网上看到些这方面的函数 但都觉得过于复杂 于是便自己写了一套 精度不高到亿 大家可以自己扩展


        public static string fnConvertToBig(string MoneyValue)
        {
            if (MoneyValue == "") return "";
            string mMinus = "";
            if (MoneyValue.StartsWith("-")) { mMinus = "负"; MoneyValue = MoneyValue.Substring(1, MoneyValue.Length - 1); }
            string[] getBit = new string[] { "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿" };
            string[] getToh = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
            string strTemp = "";
            string strValue = "";

                while (MoneyValue.Substring(MoneyValue.Length - 1, 1) == "0")
                {
                    MoneyValue = MoneyValue.Substring(0, MoneyValue.Length - 1);
                    if (MoneyValue == "") return "";
                }
                if (MoneyValue.Substring(MoneyValue.Length - 1, 1) == ".") MoneyValue = MoneyValue.Substring(0, MoneyValue.Length - 1);
                if (MoneyValue == "") return "";

                int iLen = (MoneyValue.IndexOf(".") < 0) ? MoneyValue.Length + 1 : MoneyValue.IndexOf(".") + 1;
                for (int i = 0; i < MoneyValue.Length; i++)
                {
                    strTemp = MoneyValue.Substring(i, 1);
                    if (strTemp == ".") continue;

                    if (i < MoneyValue.Length - 1)
                        if (strTemp == "0" && MoneyValue.Substring(i + 1, 1) == "0" && iLen != 6) { iLen--; continue; }

                    if ((iLen == 2 || iLen == 6) && strTemp == "0")
                        strValue += getBit[iLen];
                    else if (strTemp == "0")
                        strValue += getToh[Convert.ToInt16(strTemp)];
                    else
                        strValue += getToh[Convert.ToInt16(strTemp)] + getBit[iLen];

                    iLen--;
                }
                if (strValue.EndsWith("元")) strValue += "整";

            return mMinus + strValue;
        }

posted on 2007-06-28 16:52  王学军  阅读(318)  评论(2编辑  收藏  举报