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();

            }

  • 相关阅读:
    Ubuntu 12.04 + nginx + php5 + phpfpm安装,并进行多站点配置
    PHP的FTP类
    php操作mongodb 分组排序
    mongodb 条件操作符
    PHP匿名登录FTP
    PHP连接到FTP服务器注意事项
    Java SE第二讲 原生数据类型Primitive Data Type
    java se 第五讲 运算符续
    Java SE 第一讲 入门jdk的下载安装
    Java SE第三讲:原生数据类型的使用陷阱
  • 原文地址:https://www.cnblogs.com/tangself/p/1621410.html
Copyright © 2011-2022 走看看