这是我的代码,想要得到输入一个整形数,返回一个中文人民币表达,
比如1234,一千二百三十四元
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exam4
{
class Program
{
static void Main(string[] args)
{
bool flag = true;
while (flag)
{
Console.WriteLine("请输入一个小于百万的数字");
int i = int.Parse(Console.ReadLine());
if (i <= 9999999)
{
Money(i);
}
else
{
Console.WriteLine("输入错误,请继续输入");
}
}
}
static void Money(int n)
{
string[] StrArry = new string[n.ToString().Length];
int[] arry=new int[n.ToString().Length];
int s = n;
for (int i = 0; i < n.ToString().Length; i++)
{
arry[i] = s % 10;
s = s / 10;
}
for (int j = 0; j < arry.Length; j++)
{
switch (arry[j])
{
case 1:
StrArry[j]="一";
break;
case 2:
StrArry[j] = "二";
break;
case 3:
StrArry[j] = "三";
break;
case 4:
StrArry[j] = "四";
break;
case 5:
StrArry[j] = "五";
break;
case 6:
StrArry[j] = "六";
break;
case 7:
StrArry[j] = "七";
break;
case 8:
StrArry[j] = "八";
break;
case 9:
StrArry[j] = "九";
break;
case 0:
StrArry[j] = "零";
break;
}
switch (j)
{
case 0:
StrArry[j] += "元";
break;
case 1:
if (arry[2]==0&&arry[1]==0)
{
StrArry[j] = "";
}
else
{
StrArry[j] += "十";
}
break;
case 2:
if (arry[3] == 0&&arry[2]==0)
{
StrArry[j] = "";
}
else
{
StrArry[j] += "百";
}
break;
case 3:
StrArry[j] += "千";
break;
case 4:
StrArry[j] += "万";
break;
case 5:
StrArry[j] += "十";
break;
case 6:
StrArry[j] += "百";
break;
}
}
for (int k = arry.Length-1; k >=0; k--)
{
Console.Write(StrArry[k]);
}
Console.WriteLine();
}
}
}