小写金额转换成大写
private string RMBEncode(decimal num)
{
try
{
string str1 = "零壹贰叁肆伍陆柒捌玖";
string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分";
string str3 = "";
string str4 = "";
string str5 = "";
string ch1 = "";
string ch2 = "";
int nzero = 0;
num = Math.Round(Math.Abs(num), 2);
str4 = ((long)(num * 100M)).ToString();
int j = str4.Length;
if (j > 15)
{
return "溢出";
}
str2 = str2.Substring(15 - j);
for (int i = 0; i < j; i++)
{
str3 = str4.Substring(i, 1);
int temp = Convert.ToInt32(str3);
if ((((i != (j - 3)) && (i != (j - 7))) && (i != (j - 11))) && (i != (j - 15)))
{
if (str3 == "0")
{
ch1 = "";
ch2 = "";
nzero++;
}
else if ((str3 != "0") && (nzero != 0))
{
ch1 = "零" + str1.Substring(temp, 1);
ch2 = str2.Substring(i, 1);
nzero = 0;
}
else
{
ch1 = str1.Substring(temp, 1);
ch2 = str2.Substring(i, 1);
nzero = 0;
}
}
else if ((str3 != "0") && (nzero != 0))
{
ch1 = "零" + str1.Substring(temp, 1);
ch2 = str2.Substring(i, 1);
nzero = 0;
}
else if ((str3 != "0") && (nzero == 0))
{
ch1 = str1.Substring(temp, 1);
ch2 = str2.Substring(i, 1);
nzero = 0;
}
else if ((str3 == "0") && (nzero >= 3))
{
ch1 = "";
ch2 = "";
nzero++;
}
else if (j >= 11)
{
ch1 = "";
nzero++;
}
else
{
ch1 = "";
ch2 = str2.Substring(i, 1);
nzero++;
}
if ((i == (j - 11)) || (i == (j - 3)))
{
ch2 = str2.Substring(i, 1);
}
str5 = str5 + ch1 + ch2;
if ((i == (j - 1)) && (str3 == "0"))
{
str5 = str5 + '整';
}
}
if (num == 0M)
{
str5 = "零元整";
}
return str5;
}
catch
{
return "非法数据";
}
}
public string RMBEncode(string numstr)
{
try
{
return RMBEncode(Convert.ToDecimal(numstr));
}
catch
{
return "非数字形式!";
}
}
{
try
{
string str1 = "零壹贰叁肆伍陆柒捌玖";
string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分";
string str3 = "";
string str4 = "";
string str5 = "";
string ch1 = "";
string ch2 = "";
int nzero = 0;
num = Math.Round(Math.Abs(num), 2);
str4 = ((long)(num * 100M)).ToString();
int j = str4.Length;
if (j > 15)
{
return "溢出";
}
str2 = str2.Substring(15 - j);
for (int i = 0; i < j; i++)
{
str3 = str4.Substring(i, 1);
int temp = Convert.ToInt32(str3);
if ((((i != (j - 3)) && (i != (j - 7))) && (i != (j - 11))) && (i != (j - 15)))
{
if (str3 == "0")
{
ch1 = "";
ch2 = "";
nzero++;
}
else if ((str3 != "0") && (nzero != 0))
{
ch1 = "零" + str1.Substring(temp, 1);
ch2 = str2.Substring(i, 1);
nzero = 0;
}
else
{
ch1 = str1.Substring(temp, 1);
ch2 = str2.Substring(i, 1);
nzero = 0;
}
}
else if ((str3 != "0") && (nzero != 0))
{
ch1 = "零" + str1.Substring(temp, 1);
ch2 = str2.Substring(i, 1);
nzero = 0;
}
else if ((str3 != "0") && (nzero == 0))
{
ch1 = str1.Substring(temp, 1);
ch2 = str2.Substring(i, 1);
nzero = 0;
}
else if ((str3 == "0") && (nzero >= 3))
{
ch1 = "";
ch2 = "";
nzero++;
}
else if (j >= 11)
{
ch1 = "";
nzero++;
}
else
{
ch1 = "";
ch2 = str2.Substring(i, 1);
nzero++;
}
if ((i == (j - 11)) || (i == (j - 3)))
{
ch2 = str2.Substring(i, 1);
}
str5 = str5 + ch1 + ch2;
if ((i == (j - 1)) && (str3 == "0"))
{
str5 = str5 + '整';
}
}
if (num == 0M)
{
str5 = "零元整";
}
return str5;
}
catch
{
return "非法数据";
}
}
public string RMBEncode(string numstr)
{
try
{
return RMBEncode(Convert.ToDecimal(numstr));
}
catch
{
return "非数字形式!";
}
}
多思考,多创新,才是正道!