更改文化时如何仅保留一个标准货币符号($)?

时间:2019-06-06 14:50:18

标签: c# globalization

无论所选语言/国家/地区如何,如何使Web应用程序仅显示美元货币?

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


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

1 个答案:

答案 0 :(得分:1)

您可以尝试通过修改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;