C# 金额转换繁体大写

方式一:拼接转换

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

方式二:独立拆分打印

调用:

 string data = "";
                    List<string> lisdata = new List<string>();
                    string strCapValue = String.Format("{0:f2}", Convert.ToDouble(txtTotalCharge.Text));
                    int intDotPos = strCapValue.IndexOf("."); //点的位置
                    bool isMinus = strCapValue.Substring(0, 1) == "-" ? true : false; //判断是否负数
                    int intBeginPos = isMinus ? 1 : 0; //数值的开始位置
                    string strCapInt = strCapValue.Substring(intBeginPos, isMinus ? intDotPos - 1 : intDotPos); //取出整数部分

                    //string strCapDec = strCapValue.Substring(intDotPos + 1); //取出小数部分
                    lisdata = chang(strCapInt);
                     int Index = 0;
                    for (int i = lisdata.Count - 1; i >= 0; i--)
                    {
                        int a = 50;
                        data = lisdata[i].ToString();
                        e.Graphics.DrawString(data, new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 600 - (Index * a), 270);
                        Index++;
                    }

 

 public List<string> chang(string money)
        {
            List<string> list = new List<string>();

             list.Add("¥");
            //将小写金额转换成大写金额            
            double MyNumber = Convert.ToDouble(money);
            String[] MyBase = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
            for (int i = money.Length; i > 0; i--)
            {
                int MyData = Convert.ToInt16(money[money.Length - i].ToString());
                list.Add(MyBase[MyData]);
            }
            return list;
        }

posted @ 2013-04-17 13:58  quanxie  Views(303)  Comments(0Edit  收藏  举报