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

  • 相关阅读:
    公开课 | 高段位的测试开发工程师是如何养成的?
    测试面试真题 | 从屡次碰壁到成长蜕变,半年拿下某大厂 60W 年薪测试开发 Offer!
    Git实战(五)| 让工作更高效,搞定Git的分支管理
    双 11 钜惠 | 测试开发爆款课程全年最低价,送 Mate40Pro、Kindle、华为手环等万元豪礼!
    测试面经 | 从测试螺丝钉到大厂测试开发,三点成长心得和面试经验
    Sql Server 常用函数
    IE Web Control介绍以及TreeView 控件树形结构不能显示的问题
    一个javascript脚本写的时钟
    使用DataGrid控件实现主细表
    解决 SQL Server 耗尽内存的情况
  • 原文地址:https://www.cnblogs.com/kingreatwill/p/7064600.html
Copyright © 2011-2022 走看看