zoukankan      html  css  js  c++  java
  • C# 阿拉伯数字转中文大写,阿拉伯数字转金额

    ToRMB(12345.12) 返回: 壹万贰仟叁佰肆拾伍元壹角贰分
    ToRMB(12345) 返回: 壹万贰仟叁佰肆拾伍元整
    ToUpper(12345.12) 返回: 一万二千三百四十五点一二

    /// <summary>
    /// 数字转中文数字
    /// </summary>
    public abstract class ChinaNum
    {
        /// <summary>
        /// 数字转大写金额(壹、贰、叁)
        /// </summary>
        /// <param name="value">能转换成数字或者小数的任意类型</param>
        /// <returns>返回大写金额</returns>
        public static string ToRMB(object value)
        {
            try
            {
                string hash = double.Parse(value.ToString()).ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
                string results = Regex.Replace(hash, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[.]|$))))", "${b}${z}");
                hash = Regex.Replace(results, ".", delegate(Match m) { return "负圆空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟万億兆京垓秭穰"[m.Value[0] - '-'].ToString(); });
                if (hash.Substring(hash.Length - 1, 1) == "") { hash += ""; }
                return hash;
            }
            catch (Exception)
            {
                return "";
            }
        }
     
        /// <summary>
        /// 数字转大写数字(一、二、三)
        /// </summary>
        /// <param name="value">能转换成数字或者小数的任意类型</param>
        /// <returns>返回大写数字</returns>
        public static string ToUpper(object value)
        {
            try
            {
                string hash = double.Parse(value.ToString()).ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
                string results = Regex.Replace(hash, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[.]|$))))", "${b}${z}");
                hash = Regex.Replace(results, ".", delegate(Match m) { return "负点空〇一二三四五六七八九空空空空空空空分角十百千万亿兆京垓秭穰"[m.Value[0] - '-'].ToString(); });
                if (hash.Substring(hash.Length - 1, 1) == "") 
                {
                    hash=hash.Replace("", "");
                    return hash;
                }
                else
                {
                    hash = hash.Replace("", "").Replace("","");
                    return hash;
                }
            }
            catch (Exception)
            {
                return "";
            }
        }
     
    }
  • 相关阅读:
    c++ Oracle OCCI 编程
    linux库文件
    C/C++学习笔记 vector 和map基本操作总结
    linux 后台开发类常见问题及知识点
    Libmicrohttpd简介
    linux系统编程之进程(一):进程与程序
    回调函数
    va_start和va_end使用详解
    new在c#方法中的使用
    Android Studio快捷键
  • 原文地址:https://www.cnblogs.com/MuNet/p/5773458.html
Copyright © 2011-2022 走看看