gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:36:13 31 4
gpt4 key购买 nike

运行时

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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com