zoukankan      html  css  js  c++  java
  • C#把数字转换为大写金额

     private string ToBigNumber(long number)
            {
                // 12345 一万贰仟叁佰肆拾伍
                string[] mm ={ "", "拾", "佰", "仟", "万", "拾", "佰",

                              "仟", "亿", "拾", "佰", "仟", "万" };
                string[] dx = { "零", "壹", "贰", "叁", "肆", "伍",

                          "陆", "柒", "捌", "玖", "拾" };

                if (number == 0)
                {
                    return dx[0];
                }
                string numberStr = number.ToString();
                if (numberStr.Length > mm.Length)
                {
                    throw new UserException("can not parser number, as it it too long.");
                }
                StringBuilder buff = new StringBuilder();
                int flag = 0;
                int preNum = -1;
                for (int i = numberStr.Length - 1; i >= 0; i--)
                {
                    string currentBit = numberStr.Substring(flag++, 1);
                    if (int.Parse(currentBit) == 0)// deal with 0.
                    {
                        if (preNum != 0)// deal with 000
                        {
                            buff.Append(dx[int.Parse(currentBit)]);
                        }
                    }
                    else
                    {
                        buff.Append(dx[int.Parse(currentBit)]).Append(mm[i]);
                    }
                    preNum = int.Parse(currentBit);
                }

                //remove the latest zero.
                string result = buff.ToString();
                if (result.EndsWith(dx[0]))
                {
                    buff.Remove(buff.Length - 1, 1);
                }
                return buff.ToString();

            }

  • 相关阅读:
    【objective-c】字典快速转换为Model代码
    【objective-c】类目 延展 协议
    【objective-c】内存管理原则
    UI基础-UI基础控件(一)
    OC面向对象-OC基础早知道
    我对于编程培训班的一些看法
    如何为SQLSERVER查询分析器开启事务
    准备在博客园常驻了
    Spring学习(二)(1.Spring依赖注入的方式 2.依赖注入的类型 3.Bean的作用域 4.自动注入 5在Spring配置文件中引入属性文件6使用注解的方式 )
    Springmvc的常用注解
  • 原文地址:https://www.cnblogs.com/tangself/p/1621410.html
Copyright © 2011-2022 走看看