什么控制了。net中的CurrencyPositivePattern

时间:2021-08-16 15:17:48

When running

运行时

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));

We see a difference when using different framework versions.

在使用不同的框架版本时,我们可以看到不同之处。

v2.0.5072
2
kr 10,00

vs

vs

v4.0.30319
3
10,00 kr.

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

我为什么会看到不同的数字格式。CurrencyPositivePattern之间的机器。它是特定于还是与操作系统相关?

40,00 kr. vs kr. 20,00

40,00 kr和kr, 20,00

2 个解决方案

#1


2  

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

我为什么会看到不同的数字格式。CurrencyPositivePattern之间的机器。它是特定于还是与操作系统相关?

You are using an override (GetCultureInfo) that should NOT be affected by user preferences. According to MSDN, culture specific values are inherently unstable. I think that what you see is more of an OS thing, could change between Windows Updates. If you need something stable, in unit test for example, invariant or custom culture is the best bet.

您正在使用一个不受用户首选项影响的覆盖(GetCultureInfo)。根据MSDN,文化特有的价值本质上是不稳定的。我认为你看到的更多的是一个操作系统的东西,可以在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:

NumberFormatInfo类提供的格式化数值的特定文化数据是动态的,就像CultureInfo类提供的文化数据一样。您不应该对与特定的CultureInfo对象关联的NumberFormatInfo对象的值的稳定性做出任何假设。只有不变区域性及其关联的NumberFormatInfo对象提供的数据是稳定的。由于以下原因,其他数据可以在应用程序会话之间,甚至在单个会话中进行更改:

  • 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.

    系统更新。文化偏好,如货币符号或货币格式随时间而变化。当发生这种情况时,Windows Update包括对特定区域性的NumberFormatInfo属性值的更改。

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

    替代的文化。可以使用cultureandlocal infobuilder类来替换现有区域性的数据。

  • 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.

    对属性值的级联更改。许多与区域性相关的属性可以在运行时更改,这反过来会导致NumberFormatInfo数据更改。例如,可以通过编程或用户操作更改当前文化。当发生这种情况时,CurrentInfo属性返回的NumberFormatInfo对象将更改为与当前区域性关联的对象。

  • 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.

    用户首选项。应用程序的用户可以通过控制面板中的区域和语言选项覆盖与当前系统区域性相关的一些值。例如,用户可以选择不同的货币符号或不同的十进制分隔符符号。如果CultureInfo。UseUserOverride属性设置为true(其默认值),NumberFormatInfo对象的属性也从用户设置中检索。

#2


0  

Check Control Panel > Clock, Language, and Region > Change date, time, or number formats > Additional Settings

检查控制面板>时钟、语言和区域>更改日期、时间或数字格式>附加设置

什么控制了。net中的CurrencyPositivePattern

#1


2  

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

我为什么会看到不同的数字格式。CurrencyPositivePattern之间的机器。它是特定于还是与操作系统相关?

You are using an override (GetCultureInfo) that should NOT be affected by user preferences. According to MSDN, culture specific values are inherently unstable. I think that what you see is more of an OS thing, could change between Windows Updates. If you need something stable, in unit test for example, invariant or custom culture is the best bet.

您正在使用一个不受用户首选项影响的覆盖(GetCultureInfo)。根据MSDN,文化特有的价值本质上是不稳定的。我认为你看到的更多的是一个操作系统的东西,可以在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:

NumberFormatInfo类提供的格式化数值的特定文化数据是动态的,就像CultureInfo类提供的文化数据一样。您不应该对与特定的CultureInfo对象关联的NumberFormatInfo对象的值的稳定性做出任何假设。只有不变区域性及其关联的NumberFormatInfo对象提供的数据是稳定的。由于以下原因,其他数据可以在应用程序会话之间,甚至在单个会话中进行更改:

  • 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.

    系统更新。文化偏好,如货币符号或货币格式随时间而变化。当发生这种情况时,Windows Update包括对特定区域性的NumberFormatInfo属性值的更改。

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

    替代的文化。可以使用cultureandlocal infobuilder类来替换现有区域性的数据。

  • 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.

    对属性值的级联更改。许多与区域性相关的属性可以在运行时更改,这反过来会导致NumberFormatInfo数据更改。例如,可以通过编程或用户操作更改当前文化。当发生这种情况时,CurrentInfo属性返回的NumberFormatInfo对象将更改为与当前区域性关联的对象。

  • 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.

    用户首选项。应用程序的用户可以通过控制面板中的区域和语言选项覆盖与当前系统区域性相关的一些值。例如,用户可以选择不同的货币符号或不同的十进制分隔符符号。如果CultureInfo。UseUserOverride属性设置为true(其默认值),NumberFormatInfo对象的属性也从用户设置中检索。

#2


0  

Check Control Panel > Clock, Language, and Region > Change date, time, or number formats > Additional Settings

检查控制面板>时钟、语言和区域>更改日期、时间或数字格式>附加设置

什么控制了。net中的CurrencyPositivePattern