zoukankan      html  css  js  c++  java
  • 【原】c#实现数字金额转换成大写金额

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace RMBTest
    {
        class Program
        {
            public static string[] MyScale = { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" };
            public static string[] MyScale2 = { "分", "角" };
            public static string[] MyBase = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
            static void Main(string[] args)
            {
                while (true)
                {
                    Console.WriteLine("请输入你要转换的金额:");
                    string sMoney = Console.ReadLine();
                    string result = "";
                   
                    try
                    {
                        double dm = double.Parse(sMoney);
                        string[] array = dm.ToString().Split('.');
                        int n = 0;
                        char[] cYuan;
                        char[] cJiao;
                        if (array.Length == 2)
                        {
                            if (array[1].Length > 2)
                            {
                                Console.WriteLine("你所输入的金额错误,无法转换,请重新输入!\n");
                                continue;
                            }
                            cYuan = array[0].ToString().ToCharArray();
                            n = cYuan.Length;
                            for (int i = 0; i < cYuan.Length; i++)
                            {
                                result += MyBase[Convert.ToInt32(cYuan[i].ToString())];
                                result += MyScale[Convert.ToInt32(n) - 1];
                                n--;
                            }

                            cJiao = array[1].ToString().ToCharArray();
                            n = cJiao.Length;
                            for (int i = 0; i < cJiao.Length; i++)
                            {
                                result += MyBase[Convert.ToInt32(cJiao[i].ToString())];
                                result += MyScale2[Convert.ToInt32(n) - 1];
                                n--;
                            }
                        }
                        else
                        {
                            cYuan = dm.ToString().ToCharArray();
                            n = cYuan.Length;
                            for (int i = 0; i < cYuan.Length; i++)
                            {
                                result += MyBase[Convert.ToInt32(cYuan[i].ToString())];
                                result += MyScale[Convert.ToInt32(n) - 1];
                                n--;
                            }
                        }
                        Console.WriteLine(result);
                    }
                    catch
                    {
                        Console.WriteLine("你所输入的金额错误,无法转换,请重新输入!\n");
                        continue;
                    }
                }
            }
        }
    }

  • 相关阅读:
    李开复给学习计算机的学生的7点建议(转)
    linux 命令
    易中天的十句话
    11个笑话让你领悟人生
    心情不好的时候看看
    高校青年老师挣扎在辞职边缘 微薄工资继续啃老
    【33.00%】【vijos P1002】过河
    【33.33%】【codeforces 681D】Gifts by the List
    【19.05%】【codeforces 680D】Bear and Tower of Cubes
    【12.78%】【codeforces 677D】Vanya and Treasure
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1728121.html
Copyright © 2011-2022 走看看