• 正则一则——将金额转换成人民币大写


    首先声明,这个正则不是我写的,来源于互联网,发现好用,稍作更改,贴上分享:

    public static string ConvertToChineseMoney(double money)
            {
                if (money < 0)
                {
                    throw new ArgumentOutOfRangeException("参数money不能为负值!");
                }
                string s = money.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"); 
                s = Regex.Replace(s, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\.]|$))))", "${b}${z}"); 
                return Regex.Replace(s, ".", delegate(Match m) 
                { 
                    return "负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟萬億兆京垓秭穰"[m.Value[0] - '-'].ToString(); 
                });
            }
    

      调用该方法:

    Random r = new Random();
            for (int i = 0; i < 10; i++)
            {
                double m = r.Next() / 100.0;
                Response.Write(m + "---- " + ConvertToChineseMoney(m) + "<br/>");
            }
    

      

    运行结果:

    5970370.36---- 伍佰玖拾柒萬零叁佰柒拾元叁角陆分

    6521548.6---- 陆佰伍拾贰萬壹仟伍佰肆拾捌元陆角

    12179380.35---- 壹仟贰佰壹拾柒萬玖仟叁佰捌拾元叁角伍分

    15742735.47---- 壹仟伍佰柒拾肆萬贰仟柒佰叁拾伍元肆角柒分

    9236554.09---- 玖佰贰拾叁萬陆仟伍佰伍拾肆元零玖分

    9706980.49---- 玖佰柒拾萬陆仟玖佰捌拾元肆角玖分

    11873034.16---- 壹仟壹佰捌拾柒萬叁仟零叁拾肆元壹角陆分

    21141596.22---- 贰仟壹佰壹拾肆萬壹仟伍佰玖拾陆元贰角贰分

    17040243.44---- 壹仟柒佰零肆萬零贰佰肆拾叁元肆角肆分

    5358585.54---- 伍佰叁拾伍萬捌仟伍佰捌拾伍元伍角肆分

  • 相关阅读:
    [React Native] Error Handling and ActivityIndicatorIOS
    [GIF] Colors in GIF Loop Coder
    [React Native] Passing data when changing routes
    [Javascript] Object.freeze() vs Object.seal()
    [React Native] State and Touch Events -- TextInput, TouchableHighLight
    [GIF] GIF Loop Coder
    [GIF] GIF Loop Coder
    [Angular 2] ROUTING IN ANGULAR 2 REVISITED
    Log文件太大,手机ROM空间被占满
    strcpy,memcpy,memmove和内存重叠分析
  • 原文地址:https://www.cnblogs.com/zyzlywq/p/2323395.html
Copyright © 2020-2023  润新知