zoukankan      html  css  js  c++  java
  • 数字转换成大写

    直接上代码

    public static string ToRmb(decimal price)
            {
                string str = "零壹贰叁肆伍陆柒捌玖";
                string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分";
                string str3 = "";
                string ch2 = "";
                int nzero = 0;
                price = Math.Round(Math.Abs(price), 2);
                string str4 = ((long)(price * 100m)).ToString();
                int i = str4.Length;
                string result;
                if (i > 15)
                {
                    result = "溢出";
                }
                else
                {
                    str2 = str2.Substring(15 - i);
                    for (int j = 0; j < i; j++)
                    {
                        string str5 = str4.Substring(j, 1);
                        int temp = Convert.ToInt32(str5);
                        string ch3;
                        if (j != i - 3 && j != i - 7 && j != i - 11 && j != i - 15)
                        {
                            if (str5 == "0")
                            {
                                ch3 = "";
                                ch2 = "";
                                nzero++;
                            }
                            else if (str5 != "0" && nzero != 0)
                            {
                                ch3 = "零" + str.Substring(temp, 1);
                                ch2 = str2.Substring(j, 1);
                                nzero = 0;
                            }
                            else
                            {
                                ch3 = str.Substring(temp, 1);
                                ch2 = str2.Substring(j, 1);
                                nzero = 0;
                            }
                        }
                        else if (str5 != "0" && nzero != 0)
                        {
                            ch3 = "零" + str.Substring(temp, 1);
                            ch2 = str2.Substring(j, 1);
                            nzero = 0;
                        }
                        else if (str5 != "0" && nzero == 0)
                        {
                            ch3 = str.Substring(temp, 1);
                            ch2 = str2.Substring(j, 1);
                            nzero = 0;
                        }
                        else if (str5 == "0" && nzero >= 3)
                        {
                            ch3 = "";
                            ch2 = "";
                            nzero++;
                        }
                        else if (i >= 11)
                        {
                            ch3 = "";
                            nzero++;
                        }
                        else
                        {
                            ch3 = "";
                            ch2 = str2.Substring(j, 1);
                            nzero++;
                        }
                        if (j == i - 11 || j == i - 3)
                        {
                            ch2 = str2.Substring(j, 1);
                        }
                        str3 = str3 + ch3 + ch2;
                        if (j == i - 1 && str5 == "0")
                        {
                            str3 += '整';
                        }
                    }
                    if (price == 0m)
                    {
                        str3 = "零元整";
                    }
                    result = str3;
                }
                return result;
            }

  • 相关阅读:
    Tomcat日志、项目中的log4j日志、e.printStackTrace()——我的日志最后到底跑哪去了?
    Tomcat日志、项目中的log4j日志、控制台——我的日志最后到底跑哪去了?
    centOS7 安装redis-3.2.6
    Centos7 打开80端口防火墙命令
    CXF调用方式——使用wsdl2java(Windwos下)
    【转载】C#工具类:人民币金额转换为中文大写
    【转载】C#常用数据库Sqlserver通过SQL语句查询数据库以及表的大小
    【转载】PhpStudy修改网站根目录
    【转载】 IIS服务器防盗链设置
    【转载】C#生成图片的缩略图
  • 原文地址:https://www.cnblogs.com/kingreatwill/p/7064600.html
Copyright © 2011-2022 走看看