金額大小寫轉換正則
阿新 • • 發佈:2019-01-06
/// <summary>
/// 人民幣金額小寫轉大寫
/// </summary>
/// <param name="moneyAmount">小寫金額</param>
/// <returns>大寫金額</returns>
public string getRMB(decimal moneyAmount)
{
string s = moneyAmount.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");//d + "\n" +
string d = 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}");
string res = Regex.Replace(d, ".", delegate(Match m) { return "負元空零壹貳叄肆伍陸柒捌玖空空空空空空空分角拾佰仟萬億兆京垓秭穰"[m.Value[0] - '-'].ToString(); });
return res;
}