我测试,没发现问题。如果谁发现了问题请联系我啊。daiyanchun@hotmail.com
//金额小写转换为大写 调用参数:jesj...人民币小写金额 返回变量: name..人民币大写金额
public static string Fun_Jezh(double Jesj)
{
double JesjTemp;
string[] str1 = {"壹","贰","叁","肆","伍","陆","柒","捌","玖"};
string[] str2 = { "分","角","元","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"};
System.Text.StringBuilder sb = new System.Text.StringBuilder("");
if (Math.Abs(Jesj) <= 0.001)
{
sb.Append("");
return sb.ToString();
}
if (Jesj < 0.00)
{
sb.Append("负");
}
JesjTemp = Math.Abs(Jesj);
string sZhengSu = Math.Floor(JesjTemp).ToString(); // 整数部分
string sXiaoSu = JesjTemp.ToString("F2").Substring(JesjTemp.ToString("F2").IndexOf(".") + 1, 2); // 小数部分
string strTemp = "";
// 处理整数部分
if (sZhengSu.Substring(0, 1) != "0")
{
for (int i = 0; i < sZhengSu.ToString().Length; i++)
{
if (i > 0)
{
if (Convert.ToInt64(sZhengSu.Substring(i, 1)) == 0) // 只有本位为零时才判断上一位是否为零
{
strTemp = sZhengSu.Substring(i - 1, 1); // 取出上一位
if (strTemp == "0") // 上一位为零,若是万位,则应该加"万"字,且前面的零字应去掉,否则不做处理
{
if (sZhengSu.Length - i + 1 == 5)
{
sb.Remove(sb.Length - 1, 1);
sb.Append("万零");
}
if (sZhengSu.Length - i + 1 == 9)
{
sb.Remove(sb.Length - 1, 1);
sb.Append("亿零");
}
}
else
{
sb.Append("零");
}
}
else
{
sb.Append(str1[Convert.ToInt64(sZhengSu.Substring(i, 1)) - 1] + str2[sZhengSu.Length - i + 1]);
}
}
else
{
sb.Append(str1[Convert.ToInt64(sZhengSu.Substring(i, 1)) - 1] + str2[sZhengSu.Length - i + 1]);
}
}
// 若整数最后一位为0,则需把零字去掉.
if (Convert.ToInt64(sZhengSu.Substring(sZhengSu.Length - 1, 1)) == 0)
{
sb.Remove(sb.Length - 1, 1);
}
// 若最后一位不是元,则加元字
if (sb.ToString().Substring(sb.ToString().Length - 1, 1) != "元")
{
sb.Append("元");
}
}
// "拾"替换"壹拾"
if (sb.ToString().IndexOf("壹拾") == 0) //"壹拾"在开头,则替换
{
strTemp = sb.Remove(0, 2).ToString();
sb = new System.Text.StringBuilder("");
sb.Append("拾" + strTemp);
}
// "亿"替换"亿万"
sb.Replace("亿万", "亿");
//处理小数部分
if (sXiaoSu.Substring(0,1) == "0" && sXiaoSu.Substring(1,1) == "0")
{
if (Convert.ToInt64(sZhengSu) != 0)
{
sb.Append("整");
return sb.ToString();
}
}
if (sXiaoSu.Substring(0, 1) == "0" && sXiaoSu.Substring(1, 1) != "0")
{
if (Convert.ToInt64(sZhengSu) != 0)
{
sb.Append("零" + str1[Convert.ToInt64(sXiaoSu.Substring(1, 1)) - 1] + "分");
return sb.ToString();
}
}
if (sXiaoSu.Substring(0, 1) != "0" && sXiaoSu.Substring(1, 1) == "0")
{
sb.Append(str1[Convert.ToInt64(sXiaoSu.Substring(0, 1)) - 1] + "角");
return sb.ToString();
}
if (sXiaoSu.Substring(0, 1) != "0" && sXiaoSu.Substring(1, 1) != "0")
{
sb.Append(str1[Convert.ToInt64(sXiaoSu.Substring(0, 1)) - 1] + "角" + str1[Convert.ToInt32(sXiaoSu.Substring(1, 1)) -1] + "分");
return sb.ToString();
}
return sb.ToString();
}