C#、winfrom金额数字大小写转换
作者: 张国军_Suger
开发工具与关键技术:Visual Studio 2015、C#、.NET、winfrom
很多时候我们比如金额就需要对数字的小写转换成大写模式,因此我查找了归纳了如下方法,希望能帮到小伙伴。
实现截图::
 
实现代码::
#region 数字小写转大写
public static string CNumToCh(string X)
{
string[] num = new string[]
{
"零", "壹", "贰", "叁", "肆",
"伍", "陆", "柒", "捌", "玖"
};
string[] digit = new string[]
{
"", "拾", "佰", "仟"
};
string[] units = new string[]
{
"", "万", "亿", "万亿"
};
string returnValue = "";
int finger = 0;
int m = X.Length % 4;
int k = 0;
if (m > 0)
{
k = X.Length / 4 + 1;
}
else
{
k = X.Length / 4;
}
for (int i = k; i > 0; i--)
{
int L = 4;
if (i == k && m != 0)
L = m;
string four = X.Substring(finger, L);
int l = four.Length;
for (int j = 0; j < l; j++)
{
int n = Convert.ToInt32(four.Substring(j, 1));
if (n == 0)
{
if (j < l - 1
&& Convert.ToInt32(four.Substring(j + 1, 1)) > 0
&& !returnValue.EndsWith(num[n]))
{
returnValue += num[n];
}
}
else
{
if (!(n == 1
&& (returnValue.EndsWith(num[0]) | returnValue.Length == 0)
&& j == l - 2))
{
returnValue += num[n];
returnValue += digit[l - j - 1];
}
}
}
finger += L;
if (i < k)
{
if (Convert.ToInt32(four) != 0)
{
returnValue += units[i - 1];
}
}
else
{
returnValue += units[i - 1];
}
}
returnValue += "万元整";
return returnValue;
}
#endregion
|