>  기사  >  백엔드 개발  >  C# .net 통화 변환 예제 구현

C# .net 통화 변환 예제 구현

高洛峰
高洛峰원래의
2017-01-16 10:43:062099검색

이 문서에 설명된 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# 프로그래밍에 도움이 되길 바랍니다

C# .net 통화 더보기 변환 예시 관련 글은 PHP 중국어 홈페이지를 참고해주세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.