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.         }  
  • 相关阅读:
    《软件需求十步走》阅读笔记一
    《探索需求》读书笔记三
    2018.9.26 随笔
    2018.9.09 随笔
    日期随笔,目录
    2018.9.03 随笔
    linux signal函数遇到的问题
    关于子线程执行两次的问题
    本科四年的一点经验
    linux 网络编程 3---(io多路复用,tcp并发)
  • 原文地址:https://www.cnblogs.com/gc2013/p/3912390.html
Copyright © 2011-2022 走看看