国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C# .net實現貨幣轉換示例

2020-01-24 02:28:04
字體:
來源:轉載
供稿:網友

本文所述C# .net實現貨幣轉換示例主要利用string.format 和cultureInfo 來進行轉換。分享給大家供大家參考之用。具體方法如下:

主要實現代碼如下:

/// <summary> /// 輸入Float格式數字,將其轉換為貨幣表達方式 /// </summary> /// <param name="ftype">貨幣表達類型:0=帶¥的貨幣表達方式;1=不帶¥的貨幣表達方式;其它=帶¥的貨幣表達方式</param> /// <param name="fmoney">傳入的int數字</param> /// <returns>返回轉換的貨幣表達形式</returns> public string Rmoney(int ftype, double fmoney) {   string _rmoney;   try   {  switch (ftype)  {    case 0:  _rmoney = string.Format("{0:C2}", fmoney);  break;    case 1:  _rmoney = string.Format("{0:N2}", fmoney);  break;    default:  _rmoney = string.Format("{0:C2}", fmoney);  break;  }   }   catch   {  _rmoney = "";   }   return _rmoney; } /// <summary> /// 輸入Float格式數字,將其轉換為貨幣表達方式 /// </summary> /// <param name="ftype">貨幣表達類型:0=人民幣;1=港幣;2=美鈔;3=英鎊;4=不帶貨幣;其它=不帶貨幣表達方式</param> /// <param name="fmoney">傳入的int數字</param> /// <returns>返回轉換的貨幣表達形式</returns> public static string ConvertCurrency(decimal fmoney) {   CultureInfo cul = null;   int ftype=4;   string _rmoney=string.Empty;   try   {  switch (ftype)  {    case 0:  cul = new CultureInfo("zh-CN");//中國大陸  _rmoney = fmoney.ToString("c", cul);  break;    case 1:  cul = new CultureInfo("zh-HK");//香港  _rmoney = fmoney.ToString("c", cul);  break;    case 2:  cul = new CultureInfo("en-US");//美國  _rmoney = fmoney.ToString("c", cul);  break;    case 3:  cul = new CultureInfo("en-GB");//英國  _rmoney = fmoney.ToString("c", cul);  break;    case 4:  _rmoney = string.Format("{0:n}", fmoney);//沒有貨幣符號  break;    default:  _rmoney = string.Format("{0:n}", fmoney);  break;  }   }   catch   {  _rmoney = "";   }   return _rmoney; }

希望本文所述對大家的C#程序設計有所幫助

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海兴县| 龙海市| 黔南| 梓潼县| 鹤岗市| 镇沅| 文水县| 金湖县| 谢通门县| 兴文县| 屯门区| 汉阴县| 余干县| 大荔县| 博乐市| 安泽县| 马公市| 凤翔县| 南平市| 正镶白旗| 高邮市| 宁武县| 荥阳市| 五原县| 黄冈市| 杭锦后旗| 万源市| 云阳县| 苗栗市| 阳新县| 甘肃省| 开原市| 梓潼县| 菏泽市| 华安县| 大姚县| 沁源县| 临沧市| 舟山市| 大丰市| 山东省|