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/>"); }
const char[] CN_TABLE={'丫','儿','伞','思','物','漏','去'};使用输入input="33221.14";
string output="";
for(int i=0;i<input.Length;i++)
if(input[i]=='.')
output+="点";
else
output+=CN_TABLE[int.Parse(input[i])];---> output is "伞伞儿儿丫点丫去死"
{
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/>");
}
for(int i=0;i<input.Length;i++)
if(input[i]=='.')
output+="点";
else
output+=CN_TABLE[int.Parse(input[i])];