/// <summary>
/// 转换金额为人民币大写
/// </summary>
/// <param name="n">Int64 金额</param>
/// <returns>人民币大写</returns>
public static string ToRMB(double dn)
{
string[] strN = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
string[] strC = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
string[] strA = { "", "圆", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万亿", "拾", "佰", "仟", "亿亿", };
int[] nLoc = { 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 };
string strFrom = "";
string strTo = "";
string strChar;
int m, mLast = -1, nCount = 0;
if (strFrom.Length > strA.GetUpperBound(0) - 1) return "***拜托,这么多钱还需要数吗***";
if (dn < 0)
{
dn *= -1;
strTo = "负";
}
Int64 n1 = (Int64)dn; // 元
strFrom = n1.ToString();
for (int i = strFrom.Length; i > 0; i--)
{
strChar = strFrom.Substring(strFrom.Length - i, 1);
m = Convert.ToInt32(strChar);
if (m == 0)
{
// 连续为0时需要补齐中间单位,且只补第一次
if (nLoc[i] > 0 && nCount == 0 && strFrom.Length > 1)
{
strTo = strTo + strA[i];
nCount++;
}
}
else
{
// 补0
if (mLast == 0)
{
strTo = strTo + strC[0];
}
// 数字转换为大写
strTo = strTo + strC[m];
// 补足单位
strTo = strTo + strA[i];
nCount = 0;
}
mLast = m;
}
Int64 n2 = ((Int64)(dn * 100)) % 100; // 角分
Int64 n3 = n2 / 10; // 角
Int64 n4 = n2 % 10; // 分
string s2 = "";
if (n4 > 0)
{
s2 = strC[n4] + "分";
if (n3 > 0)
{
s2 = strC[n3] + "角" + s2;
}
}
else
{
if (n3 > 0)
{
s2 = strC[n3] + "角";
}
}
strTo = strTo + s2;
if (strTo == "") strTo = strC[0]; // 全0显示为零
else if (s2 == "") strTo = strTo + "整"; // 无角分显示整
return strTo;
}