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

  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 之货币转换的更多相关文章

  1. Analyzer中进行货币转换

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. 货币转换函数:CURRENCY_CONVERTING_FACTOR

    针对不同币别要做金额栏位转换 计算规则: 金额 = 原始金额 * 转换率 以下转自博客:https://www.cnblogs.com/sanlly/p/3371568.html 货币转换函数:CUR ...

  3. [Python3 练习] 003 货币转换

    题目:货币转换 (1) 描述 人民币和美元是世界上通用的两种货币,写一个程序进行货币间币值转换 记人民币和美元之间的汇率为:1 美元 = 6.78 人民币 程序可以接受人民币或美元输入,转换为另一种货 ...

  4. 货币转换 I

    描述 人民币和美元是世界上通用的两种货币之一,写一个程序进行货币间币值转换,其中: 人民币和美元间汇率固定为:1美元 = 6.78人民币. 程序可以接受人民币或美元输入,转换为美元或人民币输出.人民币 ...

  5. 货币转换C

    描述 人民币和美元是世界上通用的两种货币之一,写一个程序进行货币间币值转换,其中:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮ ...

  6. 货币转换B

    描述 人民币和美元是世界上通用的两种货币之一,写一个程序进行货币间币值转换,其中:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮ ...

  7. 货币转换I

    A=input() if A[0] in ['U','u']: RMB=(eval(A[3:]))*6.78 print("RMB{:.2f}".format(RMB)) else ...

  8. 1.4.2 solr字段类型--(1.4.2.3)使用货币和汇率

    1.4.2 solr字段类型 (1.4.2.1) 字段类型定义和字段类型属性. (1.4.2.2) solr附带的字段类型 (1.4.2.3) 使用货币和汇率 (1.4.2.4) 使用Dates(日期 ...

  9. Oracle的学习三:java连接Oracle、事务、内置函数、日期函数、转换函数、系统函数

    1.java程序操作Oracle java连接Oracle JDBC_ODBC桥连接 1.加载驱动: Class.forName("sun.jdbc.odbc.JdbcodbcDriver& ...

随机推荐

  1. SharePoint 2010 列表项事件接收器 ItemAdded 的使用方法

    列表项事件处理器是继承于Microsoft.SharePoint.SPItemEventReceiver的类,Microsoft.SharePoint.SPItemEventReceiver类提供了许 ...

  2. webdriver(python)学习笔记五——层级定位

    层级定位 在实际的项目测试中,经常会有这样的需求:页面上有很多个属性基本相同的元素,现在需要具体定位到其中的一个.由于属性基本相当,所以在定位的时候会有些麻烦,这时候就需要用到层级定位.先定位父元素, ...

  3. 《Python CookBook2》 第一章 文本 - 每次处理一个字符 && 字符和字符值之间的转换

    文本 - 总结: 什么是文本Python 中的string 类型是不可变类型.文本,一个字符的矩阵,每一个单独的文本快可以被缩进和组织起来. 基本的文本操作①解析数据并将数据放入程序内部的结构中:②将 ...

  4. DIV+CSS常见问题:DIV如何设置一个像素高度?

    CSS如何控制DIV实现1像素高度呢?问题看起来很简单,但万恶的IE6会让你很麻烦,不过解决办法很多,本文将介绍最简单的一种:DIV{height:1px;line-height:1px;font-s ...

  5. OpenGL超级宝典第5版&&缓冲区

    缓冲区有很多用途:可以保存顶点数据,像素数据,纹理数据,着色器处理的输入,不同着色器阶段的输出. 缓冲区保存在GPU内存中,提供高速有效的访问.   像素缓冲区对象: GLuint pixBuffer ...

  6. HDU 5607 graph(DP+矩阵乘法)

    [题目链接] http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=663&pid=1002 [题意] 给定一个有向 ...

  7. codeforce 702C Cellular Network 二分答案

    http://codeforces.com/contest/702 题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄 思路:直接二分答案 二分太弱,调了半天..... // #pragma co ...

  8. Java ArrayList Sort

    Collections.sort(hits_list, new Comparator<ScoreDoc>(){ @Override public int compare(ScoreDoc ...

  9. Codeforces 367

    A. Sereja and Algorithm 水题不解释. B. Sereja ans Anagrams 模p同余的为一组,随便搞. C. Sereja and the Arrangement of ...

  10. Android实例-读取设备联系人(XE8+小米2)

    相关资料: http://www.colabug.com/thread-1071065-1-1.html 结果: 1.将权限打开Read contacts设置为True,不然报图一的错误. 2.搜索空 ...