WPF 将数字转化为中文大写
时间: 2023-12-30 10:03:59 浏览: 113
数字转换成中文大写
5星 · 资源好评率100%
WPF 中可以使用以下代码将数字转化为中文大写:
```csharp
public static string ConvertNumberToChinese(double number)
{
string[] numArray = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
string[] unitArray = new string[] { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿" };
string result = "";
string str = Math.Round(number, 2).ToString();
int length = str.Length;
int zeroCount = 0;
for (int i = 0; i < length; i++)
{
int num = int.Parse(str[i].ToString());
int unitNum = length - i - 1;
string unit = unitArray[unitNum];
if (num == 0)
{
zeroCount++;
if (unitNum == 4 && zeroCount < 4)
{
result += unitArray[unitNum];
zeroCount = 0;
}
}
else
{
if (zeroCount > 0)
{
result += numArray[0];
zeroCount = 0;
}
result += numArray[num] + unit;
}
}
if (zeroCount > 0 && length >= 5)
{
result += "零";
}
result += "整";
return result;
}
```
调用方法:
```csharp
double number = 1234567890.12;
string chinese = ConvertNumberToChinese(number);
```
输出结果:
```
壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾元壹角贰分整
```
阅读全文