首页 > Web开发 > 详细

C#.net 之货币转换

时间:2014-08-14 15:54:38      阅读:335      评论:0      收藏:0      [点我收藏+]

利用string.format 和cultureInfo 来进行转换

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

 

C#.net 之货币转换,布布扣,bubuko.com

C#.net 之货币转换

原文:http://www.cnblogs.com/gc2013/p/3912390.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!