将数值转换为大写的方法
> 使用自定义方法实现基本的整数转大写
class Program
{
static string[] units = { "", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
static string[] chineseUnits = { "", "拾", "佰", "仟" };
static string NumberToChinese(int number)
{
if (number == 0)
{
return "零";
}
string result = "";
int unitIndex = 0;
while (number > 0)
{
int digit = number % 10;
if (digit!= 0)
{
result = units[digit] + chineseUnits[unitIndex] + result;
}
else if (result.Length > 0 && result[0]!= '零')
{
result = "零" + result;
}
number /= 10;
unitIndex++;
}
return result;
}
static void Main()
{
int number = 1234;
Console.WriteLine(NumberToChinese(number));
}
}

苏公网安备32021402003127号