将小写金额转换成为大写

如果有Bug,请留言我我及时的改。

public string FormatMoneyToUpper(decimal money)
    {
        bool isTrue = false;//判定是否为负值,是则为True否则为False
        if (money < 0)
        {
            //如果该值是负数,那先将该值转换为正数,然后将Istrue标记为True
            money=Math.Abs(money);
            isTrue = true;
        }
        //先转换为小数点后两位
        string oldNum = Math.Round(money, 2).ToString();
        //如果字符串中不存在"."那么就将他加".00" ,如果是一位小数则在后面补0;
        if (oldNum.IndexOf(".") == -1)
        { oldNum = oldNum + ".00"; }
        else if (oldNum.IndexOf(".") == oldNum.Length - 2)
        { oldNum = oldNum + "0";}

        char[] charArr = oldNum.ToCharArray();
        string upper="";
        string upperA = "";
        string[] upperNum = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        string[] unit = { "分", "角", "圆", "拾", "佰", "仟", "万", "亿" };
        int len = 1;
        while (len <= oldNum.Length)
        {
            //判断每位对应的大写
            switch (oldNum.Substring(oldNum.Length - len, 1))
            {
                case ".": upperA = "圆"; break;
                case "0": upperA = "零"; break;
                case "1": upperA = "壹"; break;
                case "2": upperA = "贰"; break;
                case "3": upperA = "叁"; break;
                case "4": upperA = "肆"; break;
                case "5": upperA = "伍"; break;
                case "6": upperA = "陆"; break;
                case "7": upperA = "柒"; break;
                case "8": upperA = "捌"; break;
                case "9": upperA = "玖"; break;
            }
            //将数值后添加单位
            switch (len)
            {
                case 1: upperA = upperA + "分"; break;
                case 2: upperA = upperA + "角"; break;
                case 3: upperA = upperA + ""; break;
                case 4: upperA = upperA + ""; break;
                case 5: upperA = upperA + "拾"; break;
                case 6: upperA = upperA + "佰"; break;
                case 7: upperA = upperA + "仟"; break;
                case 8: upperA = upperA + "萬"; break;
                case 9: upperA = upperA + "拾"; break;
                case 10: upperA = upperA + "佰"; break;
                case 11: upperA = upperA + "仟"; break;
                case 12: upperA = upperA + "億"; break;
                case 13: upperA = upperA + "拾"; break;
                case 14: upperA = upperA + "佰"; break;
                case 15: upperA = upperA + "仟"; break;
                case 16: upperA = upperA + "萬"; break;
                default: upperA += ""; break;
            }
            upper = upperA + upper;
            len++;
        }
        upper = upper.Replace("零拾", "零");// 处理101   壹佰零拾壹
        upper = upper.Replace("零佰", "零");// 处理1001   壹仟零佰零拾壹
        upper = upper.Replace("零仟", "零");// 处理10001   壹萬零仟零佰零拾壹
        upper = upper.Replace("零零零", "零");//经过上面处理可能会出现  例如10001 就会是   壹萬零零零壹
        upper = upper.Replace("零零", "零");//经过上面处理可能会出现  例如1001 就会是   壹仟零零壹
        upper = upper.Replace("零角零分", "整");//1001.00 会出现 零角零分
        upper = upper.Replace("零分", "整");//1001.50  会出现 零分
        upper = upper.Replace("零角", "零");//1001.05  会出现 零角
        upper = upper.Replace("零億零萬零圆", "億圆");//
        upper = upper.Replace("億零萬零圆", "億圆");
        upper = upper.Replace("零億零萬", "億");//10000000001   壹佰零億零萬零壹圆整
        upper = upper.Replace("零萬零圆", "萬圆");
        upper = upper.Replace("零億", "億");
        upper = upper.Replace("零萬", "萬");
        upper = upper.Replace("零圆", "圆");
        upper = upper.Replace("億萬", "億");
        upper = upper.Replace("零零", "零");
        //对零圆以下处理
        if (upper.Substring(0, 1) == "圆")
        { upper = upper.Substring(1, upper.Length - 1); }
        if (upper.Substring(0, 1) == "角")
        { upper = upper.Substring(1, upper.Length - 1); }
        if (upper.Substring(0, 1) == "分")
        { upper = upper.Substring(1, upper.Length - 1); }
        if (upper.Substring(0, 1) == "零")
        { upper = upper.Substring(1, upper.Length - 1); }
        if (upper.Substring(0, 1) == "整")
        { upper = "零圆整"; }
        if (isTrue)
        { upper = "负" + upper; }
        return upper;
    }


posted @ 2012-03-13 11:38  Bodi  阅读(219)  评论(0编辑  收藏  举报