C#编写数字转换中文算法

C#编写数字转换中文算法

最近由于项目的原因,需要C#编写数字转换中文算法,先在网了找了一下,结果发现无一列外都是用C#编写数字转换中文算法来实现的,所以想写个另外的算法;因为本人是学数学出身的,所以用纯数学的方法实现。

C#编写数字转换中文算法代码

 

 
 
 
  1. static void Main(string[] args)  
  2. {  
  3.  
  4. Console.WriteLine("请输入金额");  
  5. string inputNum = Console.ReadLine();  
  6. while (inputNum != "exit")  
  7. {  
  8.  
  9. //货币数字转化类  
  10. NumCast nc = new NumCast();  
  11.  
  12.  
  13. if (nc.IsValidated<string>(inputNum))  
  14. {  
  15. try  
  16. {  
  17. string chineseCharacter = nc.ConvertToChinese(inputNum);  
  18. Console.WriteLine(chineseCharacter);  
  19. }  
  20. catch (Exception er)  
  21. {  
  22. Console.WriteLine(er.Message);  
  23. }  
  24. }  
  25. else  
  26. {  
  27. Console.WriteLine("不合法的数字或格式");  
  28. }  
  29.  
  30. Console.WriteLine("\n请输入金额");  
  31. inputNum = Console.ReadLine();  
  32.  
  33. }  
  34. Console.ReadLine();  

【编辑推荐】

  1. 如何用C#和ADO.NET访问
  2. 浅析C# Switch语句
  3. C#验证输入方法详解
  4. 简单介绍C# 匿名方法
  5. C# FileSystemWatcher对象
THE END