Skip to content

Instantly share code, notes, and snippets.

@yhnbgfd
Created December 26, 2017 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhnbgfd/83da3cb8fb71791ea8160c46a3a3afb8 to your computer and use it in GitHub Desktop.
Save yhnbgfd/83da3cb8fb71791ea8160c46a3a3afb8 to your computer and use it in GitHub Desktop.
数字金额转换成中文金额
using System;
using System.Text.RegularExpressions;
namespace System.Extended
{
public static class Convert
{
public static string ToChinese(this decimal 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(); });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment