zoukankan      html  css  js  c++  java
  • 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;
            }

  • 相关阅读:
    conda配置文件.condarc
    conda--python环境管理工具
    angular引入UEditor
    spark-MD5文件MD5加密
    js数组切片
    Window.postMessage() 解决父页面与iframe之间跨域通信问题,实时获取iframe消息动态
    博客园自定义主题
    html-标签转义-反转义
    uni-app获取通讯录信息 获取手机号
    LeetCode第243场周赛
  • 原文地址:https://www.cnblogs.com/quanxie/p/3026139.html
Copyright © 2011-2022 走看看