C#.net 貨幣格式轉換

來源:互聯網
上載者:User

標籤:os   ar   for   sp   on   c   ef   r   new   

  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.         } 

 

C#.net 貨幣格式轉換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.