zoukankan      html  css  js  c++  java
  • C#.net 之货币转换

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

    C#代码  收藏代码
    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.         }  
  • 相关阅读:
    git 命令手册
    leetcode #7 revert integer 问题
    leetcode #1 twoSum问题:简单实用哈希表
    c++模板函数分离编译的问题
    matlab 与c/c++ 混合MEX的编程
    springboot项目打war包
    springboot-jpa多数据源
    springboot使用RestTemplate+httpclient连接池发送http消息
    IDEA如何安装lombok
    Springboot如何启用文件上传功能
  • 原文地址:https://www.cnblogs.com/gc2013/p/3912390.html
Copyright © 2011-2022 走看看