直接来看代码:
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---- 伍佰叁拾伍 捌仟伍佰捌拾伍元伍角肆分
新闻热点
疑难解答
图片精选