博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#.net 货币格式转换
阅读量:4567 次
发布时间:2019-06-08

本文共 1451 字,大约阅读时间需要 4 分钟。

  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

你可能感兴趣的文章
命令服务器linux中tftp服务器设置及测试,图解
查看>>
Java Binary Search
查看>>
RPM包制作总结篇
查看>>
设计模式(六)—原型模式Prototype(创建型)
查看>>
Windows下配置Jenkins 实现自动发布maven项目至tomcat(svn+maven+tomcat)
查看>>
RFID电动车防盗系统的几个问题
查看>>
PostgreSQL 建库建表脚本
查看>>
第四次作业 何雅
查看>>
input 批量修改
查看>>
Request.ServerVariables
查看>>
Python graphlab create 安装
查看>>
使用mocha测试
查看>>
C++内存精细管理-----2
查看>>
jQuery 学习笔记
查看>>
Excel Service备注
查看>>
dotnet core on Linux 环境搭建及入门demo
查看>>
js 两个日期之间有多少个星期几
查看>>
BZOJ 1968 [Ahoi2005]COMMON 约数研究
查看>>
郭佳庆(201551296)第一次作业:统计软件简介与数据操作
查看>>
HTTP vs HTTPS
查看>>