• 数字转换成大写


    直接上代码

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

  • 相关阅读:
    Scrum会议5
    小组项目alpha发布的评价
    第二阶段冲刺记录三
    第二阶段冲刺记录二
    第13周学习进度
    第二阶段冲刺记录1
    《人月神话》阅读笔记01
    第12周学习进度
    意见汇总
    双人结对,四则运算(三阶段)
  • 原文地址:https://www.cnblogs.com/kingreatwill/p/7064600.html
Copyright © 2020-2023  润新知