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

  • 相关阅读:
    1.3.6 详解build.gradle文件——Android第一行代码(第二版)笔记
    1.3.5 详解项目中的资源——Android第一行代码(第二版)笔记
    1.3.4分析你的第一个Android程序——Android第一行代码(第二版)笔记
    1.3创建你的第一个Android项目——Android第一行代码(第二版)笔记
    1.2搭建开发环境——Android第一行代码(第二版)笔记
    1.1.3 Android应用开发特色——Android第一行代码(第二版)笔记
    函数与方法的区别
    你真的知道敏捷到底是什么吗?
    某个应用的CPU使用率居然达到100%,我该怎么办?
    异常 lock buffer failed for format 0x23
  • 原文地址:https://www.cnblogs.com/quanxie/p/3026139.html
Copyright © 2011-2022 走看看