开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 3985|回复: 1

[源码] 阿拉伯数字转中文大写,阿拉伯数字转金额

[复制链接]

0

精华

275

贡献

2247

赞扬

正版授权组

Rank: 14Rank: 14Rank: 14Rank: 14

帖子
211
软币
7145
在线时间
633 小时
注册时间
2013-12-13
发表于 2015-4-9 14:46:09 | 显示全部楼层 |阅读模式
本帖最后由 66767376 于 2015-4-9 15:35 编辑

都是我项目里的代码,安全可靠,求贡献值啊。


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


[C#] 纯文本查看 复制代码
    /// <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 "〇";
            }
        }

    }

评分

参与人数 3贡献 +3 赞扬 +3 收起 理由
xhdyhzw + 1 很给力
威廉乔克斯 + 1 赞一个
羽叶 + 3 + 1 赞一个

查看全部评分

回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
13
软币
128
在线时间
8 小时
注册时间
2014-12-21
发表于 2015-4-13 10:09:45 | 显示全部楼层
这是什么了???
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-5-3 04:43

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表