算法:网上找的小写金额转为大写,看不懂,高手帮忙解释一下
说说其流程         
            public string chang(string money)
        {
            //将小写金额转换成大写金额           
            double MyNumber = Convert.ToDouble (money );
            String[] MyScale = { "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" };
            String[] MyBase = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
            String M = "";
            bool isPoint = false;
            if (money.IndexOf(".") != -1)
            {
                money = money.Remove(money.IndexOf("."), 1);
                isPoint = true;
            }
            for (int i = money.Length; i > 0; i--)
            {
                int MyData = Convert.ToInt16(money[money.Length - i].ToString ());//?
                M += MyBase[MyData];//?
                if (isPoint==true)
                {
                    M += MyScale[i - 1];//?
                }
                else
                {
                    M += MyScale[i + 1];//?
                }
            }
            return M;
        }

解决方案 »

  1.   

       public string chang(string money) 
            { 
                //将小写金额转换成大写金额          
                double MyNumber = Convert.ToDouble (money ); 
                String[] MyScale = { "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" }; //定义单位字符串数组
                String[] MyBase = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; //定义数字字符串数组
                String M = ""; 
                bool isPoint = false; 
                if (money.IndexOf(".") != -1) 
                { 
                    money = money.Remove(money.IndexOf("."), 1); 
                    isPoint = true; 
                } 
                for (int i = money.Length; i > 0; i--) 
                { 
                    int MyData = Convert.ToInt16(money[money.Length - i].ToString ());//获取money中的数字,并转换为浮点型
                    M += MyBase[MyData];//从mybase中取出同index的数字的汉字字符
                    if (isPoint==true) 
                    { 
                        M += MyScale[i - 1];//获取单位
                    } 
                    else 
                    { 
                        M += MyScale[i + 1];//获取单位
                    } 
                } 
                return M; //返回转换的金额字符串
            }