C#:小写金额转换为大写

        #region 小写金额转换为大写
public static string CurrToChnNum(double Currnum)
{
string sResult = "";
if (Math.Abs(Currnum) < 1e-20)
return "零圆整";
if (Currnum < 1e-20)
sResult = "负";
sResult = sResult + StringToChnNum(Math.Abs(Math.Round(Currnum, 2)).ToString());
return sResult;
}
private static string FourNumToChnNum(string Str, string ChnNum, ref Boolean Pre)
{
string[] Digits = {"零", "壹", "贰", "叁", "肆",
"伍", "陆", "柒", "捌", "玖"};
int i, j, Len;
string sResult = "";
Len = Str.Length;
for (i = 0; i < Len; i++)
{
j = Str[i] - 48;
if (0 == j)
Pre = true;
else
{
if (Pre) sResult = sResult + "零";
sResult = sResult + Digits[j] + ChnNum.Substring(Len - i - 1, 1);
Pre = false;
}
}
return sResult.Trim();
}
//将格式化好的小写串转换为大写串
private static string StringToChnNum(string str)
{
const string ChnNum1 = "圆万亿兆";
int i, Len, Len1, Level, Start;
string s1; string s;
Boolean Pre;
string sResult = "";
Len = str.IndexOf('.');
Level = (Len + 3) / 4;
Len1 = Len % 4;
if (0 == Len1) Len1 = 4;
Start = 0;
for (i = 1; i <= Level; i++)
{
Pre = false;
s = str.Substring(Start, Len1);
s1 = FourNumToChnNum(s, " 拾佰仟", ref Pre);
if (s1.Length > 0)
sResult = sResult + s1 + ChnNum1.Substring(Level - i, 1);
Start = Start + Len1;
Len1 = 4;
}
Pre = false;
s1 = FourNumToChnNum(str.Substring(Len + 1, Math.Min(2, str.Length - Len - 1)), "分角", ref Pre);
//s1 = "";
if (s1.Length == 0)
s1 = "整";
sResult = sResult + s1;
return sResult;
}
#endregion
上一篇:ftk学习记(list篇)


下一篇:[转载] ZooKeeper实现分布式队列Queue