c# - 什么控制 .NET 中的 CurrencyPositivePattern

标签 c# .net locale

运行时

var x = 10.0M;

Console.WriteLine(typeof(Program).Assembly.ImageRuntimeVersion);

var culture = System.Globalization.CultureInfo.GetCultureInfo("da-DK");

Console.WriteLine(culture.NumberFormat.CurrencyPositivePattern);
Console.WriteLine(x.ToString("C", culture));

我们在使用不同的框架版本时看到了差异。

v2.0.5072
2
kr 10,00

对比

v4.0.30319
3
10,00 kr.

另外,为什么我会在机器之间看到不同的 NumberFormat.CurrencyPositivePattern。它是特定于框架还是与操作系统相关?

40,00 kr.对比kr. 20,00

最佳答案

Also why would I see different a NumberFormat.CurrencyPositivePattern between machines. Is it framework specific or related to the OS?

您正在使用不应受用户首选项影响的覆盖 (GetCultureInfo)。根据MSDN ,特定于文化的值(value)观本质上是不稳定的。我认为您看到的更多是操作系统的东西,可能会在 Windows 更新之间发生变化。如果您需要稳定的东西,例如在单元测试中,不变或自定义文化是最好的选择。

NumberFormatInfo and dynamic data

The culture-specific data for formatting numeric values provided by the NumberFormatInfo class is dynamic, just like the cultural data provided by the CultureInfo class. You should not make any assumptions about the stability of values for NumberFormatInfo objects that are associated with particular CultureInfo objects. Only the data provided by the invariant culture and its associated NumberFormatInfo object is stable. Other data can change between application sessions, or even within a single session, for the following reasons:

  • System updates. Cultural preferences such as the currency symbol or currency formats change over time. When this happens, Windows Update includes changes to the NumberFormatInfo property value for a particular culture.

  • Replacement cultures. The CultureAndRegionInfoBuilder class can be used to replace the data of an existing culture.

  • Cascading changes to property values. A number of culture-related properties can change at run time, which, in turn, causes NumberFormatInfo data to change. For example, the current culture can be changed either programmatically or through user action. When this happens, the NumberFormatInfo object returned by the CurrentInfo property changes to an object associated with the current culture.

  • User preferences. Users of your application might override some of the values associated with the current system culture through the region and language options in Control Panel. For example, users might choose a different currency symbol or a different decimal separator symbol. If the CultureInfo.UseUserOverride property is set to true (its default value), the properties of the NumberFormatInfo object are also retrieved from the user settings.

关于c# - 什么控制 .NET 中的 CurrencyPositivePattern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49926486/

相关文章:

c# - 将返回值错误报告提升为异常

c# - 如何调用 main 方法或重启应用程序控制台?

C# 更改系统语言环境

PHP gettext() - putenv 和 setlocale

c - setlocale() 没有按预期工作

c# - 解析 DataType 时 JSON 反序列化到 DataTable 问题

c# - 类由于其保护级别而无法访问

.net - 对于使用 CQRS 的 ASP.NET MVC 应用程序来说,什么是好的读取模型?

c# - 这个函数的执行顺序是什么 : var queryResult = names. OrderBy(item => item).Where(it => it.StartsWith ("S"))

c# - 笛卡尔积或 2 个大文本文件的最佳方法