C#.net 货币格式转换

  1. /// <summary>  
  2. /// 输入Float格式数字,将其转换为货币表达方式  
  3. /// </summary>  
  4. /// <param name="ftype">货币表达类型:0=带¥的货币表达方式;1=不带¥的货币表达方式;其它=带¥的货币表达方式</param>  
  5. /// <param name="fmoney">传入的int数字</param>  
  6. /// <returns>返回转换的货币表达形式</returns>  
  7. public string Rmoney(int ftype, double fmoney)  
  8.         {  
  9. string _rmoney;  
  10. try  
  11.             {  
  12. switch (ftype)  
  13.                 {  
  14. case 0:  
  15.                         _rmoney = string.Format("{0:C2}", fmoney);  
  16. break;  
  17. case 1:  
  18.                         _rmoney = string.Format("{0:N2}", fmoney);  
  19. break;  
  20. default:  
  21.                         _rmoney = string.Format("{0:C2}", fmoney);  
  22. break;  
  23.                 }  
  24.             }  
  25. catch  
  26.             {  
  27.                 _rmoney = "";  
  28.             }  
  29. return _rmoney;  
  30.         }  
  31. /// <summary>  
  32. /// 输入Float格式数字,将其转换为货币表达方式  
  33. /// </summary>  
  34. /// <param name="ftype">货币表达类型:0=人民币;1=港币;2=美钞;3=英镑;4=不带货币;其它=不带货币表达方式</param>  
  35. /// <param name="fmoney">传入的int数字</param>  
  36. /// <returns>返回转换的货币表达形式</returns>  
  37. public static string ConvertCurrency(decimal fmoney)  
  38.         {  
  39.             CultureInfo cul = null;  
  40. int ftype=4;  
  41. string _rmoney=string.Empty;  
  42. try  
  43.             {  
  44. switch (ftype)  
  45.                 {  
  46. case 0:  
  47.                         cul = new CultureInfo("zh-CN");//中国大陆  
  48.                         _rmoney = fmoney.ToString("c", cul);  
  49. break;  
  50. case 1:  
  51.                         cul = new CultureInfo("zh-HK");//香港  
  52.                         _rmoney = fmoney.ToString("c", cul);  
  53. break;  
  54. case 2:  
  55.                         cul = new CultureInfo("en-US");//美国  
  56.                         _rmoney = fmoney.ToString("c", cul);  
  57. break;  
  58. case 3:  
  59.                         cul = new CultureInfo("en-GB");//英国  
  60.                         _rmoney = fmoney.ToString("c", cul);  
  61. break;  
  62. case 4:  
  63.                         _rmoney = string.Format("{0:n}", fmoney);//没有货币符号  
  64. break;  
  65. default:  
  66.                         _rmoney = string.Format("{0:n}", fmoney);  
  67. break;  
  68.                 }  
  69.             }  
  70. catch  
  71.             {  
  72.                 _rmoney = "";  
  73.             }  
  74. return _rmoney;  
  75.         } 

 

转载于:https://www.cnblogs.com/iwin9999/p/3995261.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值