回 帖 发 新 帖 刷新版面

主题:高手们,过来看看呀!!

using System;
class RenminbiUper
{
    static string[] UPerMoney={"","壹","贰","叁","肆","伍","陆","柒","捌","玖"} ;
    static string[] Digit={"","","拾","佰","千"};
    static string[] Ling ={"","零"};
    static string[] Wan ={"","万"};
    static string[] Yi={"","亿"};
    public static void toUper(System.Decimal num)
    {
        char[]moneyNumber;
        if(num<1)
        {
            moneyNumber=("0"+num.ToString(".00")).TocharArray();
        }
        else
            moneyNumber=( num.ToString(".00")).TocharArray();  
        Console.WriteLine(" moneyNumber");
        int length= moneyNumber.Length;
        int curValue;
        int curDigit;
        int perValue=1;
        int indexOfDigit;
        int perValueIsZero;
        int isWan=0;
        int isYi=0;
        string Yuan ="";
        bool flag =false;
        if( moneyNumber[0]!='0')
        {
            // moneyNumber="0"+ moneyNumber;
            //    Console.WriteLine( moneyNumber);
            for(int i=0;i<length-3;i++);
        {
            perValueIsZero=0;
            curDigit=length-3-i;
            if(curDigit<9)
                isYi=0;
            if(curDigit<5||(curDigit<13&&curDigit>8) )
            {
                flag=false;
                isWan=0;
            }
            if(i>0&&perValue==0)
                perValueIsZero=1;
            if(cueDigit<5)
                indexOfDigit=curDigit%5;
            else if(cueDigit<9)
            {
                indexOfDigit=(curDigit-4)%5;
            } 
            else if(curDigit<=13)
                indexOfDigit=(curDigit-8)%5;
            else 
                indexOfDigit=(curDigit-12)%5;
            curValue=Convert.ToInt32(moneyNumber[i].ToString());
            if((curDigit>=5&&curDigit<9||curDigit>12)&&flag==false)
            {
                flag=curValue==0&&length>11?false:true;
            }     
            if((curDigit>=5||curDigit==13||curDigit>12)&&flag==9)
            {
                if(flag)
                    isWan=1;
                if(curDigit==0)
                    perValueIsZero=0;
            }
            if(curDigit==9) 
                isYi=1;
            perValue=curValue;
            if(curValue!=0||(curValue==0&&(curDigit==5||curDigit==13||curDigit==9)) )
            {
                Yuan+=Ling[perValueIsZero]+UperMoney[curValue]+Digit[indexOfDigit]+Wan[isWan]+Yi[isYi];
            }
        }
            Yuan+="元";
            if(moneyNumber[length-1]=='0'&&moneyNumber[length-2]=='0')
                Yuan+="整";
            else 
            {
                if( moneyNumber[length-4]=='0')
                    Yuan+="零";
                if(moneyNuber[length-1]=='0')
                    Yuan+=UperMoney[Convert.ToInt32(moneyNumber[length-2].ToString())]+"角";
                else if( moneyNumber[length-2]=='0')
                {
                    if( moneyNumber[length-4]!='0') 
                        Yuan+="零";
                    Yuan+=UperMoney[Convert.ToInt32(moneyNumber[length-1].ToString())]+"分";
                }
                else 
                    Yuan+=UperMoney[Convert.ToInt32(moneyNumber[length-2].ToString())]+"角"+UperMoney[Convert.ToInt32(moneyNumber[length-1].ToString())]+"分";
            }
        }
        else
        {
            if(moneyNumber[length-4]=='0')
                Yuan+="";
            if(moneyNumber[length-1]=='0')
                Yuan+=UperMoney[Convert.ToInt32(moneyNumber[length-2].ToString())]+"角";
            else if(moneyNumber[length-2]=='0')
            {
                if(moneyNumber[length-4]!='0')
                    Yuan+="";
                Yuan+=UperMoney[Convert.ToInt32(moneyNumber[length-1].ToString())]+"分";
            }
            else
                Yuan+=UperMoney[Convert.ToInt32(moneyNumber[length-2].ToString())]+"角"+UperMoney[Convert.ToInt32(moneyNumber[length-1].ToString())]+"分";
        }
        Console.WriteLine(Yuan);
    }
    [STAThread]
    static void mmain(string[] args)
    {
    System.Decimal d=0;
        bool flag=true;
        bool error=false;
        do
        {
        if(error)
            System.Console.WriteLine("输入格式不正确,请重新输入!!");
         Console.Write("请输入转换数(16位整数,0退出):");
            try
            {
                d=Convert.ToDecimal(Console.ReadLine());
                Console.WriteLine(d);
                /*
                if(d==0) break;
                if(d.ToString(".00").length>19)
                {
                error=true;
                continue;
                */
                toUper(d);
                error=false;
                break;
            } 
            catch
            {error=true;}
            }
        while(flag);
        }
    }
有什么问题吗?
麻烦修改一下。

回复列表 (共1个回复)

沙发

最头痛就是贴代码,又不说是什么异常.

我来回复

您尚未登录,请登录后再回复。点此登录或注册