C#编写数字转换中文算法
最近由于项目的原因,需要C#编写数字转换中文算法,先在网了找了一下,结果发现无一列外都是用C#编写数字转换中文算法来实现的,所以想写个另外的算法;因为本人是学数学出身的,所以用纯数学的方法实现。
C#编写数字转换中文算法代码
static void Main(string[] args)
{
Console.WriteLine("请输入金额");
string inputNum = Console.ReadLine();
while (inputNum != "exit")
{
//货币数字转化类
NumCast nc = new NumCast();
if (nc.IsValidated<string>(inputNum))
{
try
{
string chineseCharacter = nc.ConvertToChinese(inputNum);
Console.WriteLine(chineseCharacter);
}
catch (Exception er)
{
Console.WriteLine(er.Message);
}
}
else
{
Console.WriteLine("不合法的数字或格式");
}
Console.WriteLine("\n请输入金额");
inputNum = Console.ReadLine();
}
Console.ReadLine();
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
【编辑推荐】