首页 > 解决方案 > 改变文化时如何只保留一个标准货币符号($)?

问题描述

无论选择何种语言/国家,如何使网络应用程序仅以美元显示货币?

SetCulture(string culture)
   {
     CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture);
     CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(culture);
   }  


Text = String.Format("{0:C}", item.TotCostDay);

标签: c#globalization

解决方案


您可以尝试通过修改创建Clone当前文化NumberFormat.Currency...

CultureInfo culture = CultureInfo.CurrentCulture.Clone() as CultureInfo;

CultureInfo usCulture = CultureInfo.GetCultureInfo("en-US");

// Dollar symbol - $
culture.NumberFormat.CurrencySymbol = usCulture.NumberFormat.CurrencySymbol;

// And (may be) some US currency patterns
culture.NumberFormat.CurrencyDecimalDigits = usCulture.NumberFormat.CurrencyDecimalDigits;
culture.NumberFormat.CurrencyPositivePattern = usCulture.NumberFormat.CurrencyPositivePattern;
culture.NumberFormat.CurrencyNegativePattern = usCulture.NumberFormat.CurrencyNegativePattern;

CultureInfo.CurrentCulture = culture;

推荐阅读