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

  • 相关阅读:
    OpenCV 在android studio 中的用法
    Python中用requests处理cookies的3种方法
    Jmeter利用正则表达式提取器提取登录cookie供下一步使用
    vue项目 el-tree的界面自定义 实现增删改查操作
    PostgreSQL高可用方案-patroni+etcd+vipmanager(二)
    PostgreSQL高可用方案-patroni+etcd+vipmanager(一)
    【转载】Linux下PostgreSQL主备环境搭建和切换
    一些自定义 PostgreSQL 随机数据生成器 —— Some self-defined PostgreSQL random data generators
    ClickHouse 简单使用(六)
    ClickHouse 简单使用(五)
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1728121.html
Copyright © 2011-2022 走看看