简体   繁体   English

什么控制.NET中的CurrencyPositivePattern

[英]What controls the CurrencyPositivePattern in .NET

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. 另外,为什么我会在机器之间看到不同的NumberFormat.CurrencyPositivePattern Is it framework specific or related to the OS? 它是特定于框架还是与操作系统相关?

40,00 kr. 40,00 kr。 vs kr. vs kr。 20,00 20,00

Also why would I see different a NumberFormat.CurrencyPositivePattern between machines. 另外,为什么我会在机器之间看到不同的NumberFormat.CurrencyPositivePattern。 Is it framework specific or related to the OS? 它是特定于框架还是与操作系统相关?

You are using an override (GetCultureInfo) that should NOT be affected by user preferences. 您正在使用不应受用户首选项影响的覆盖(GetCultureInfo)。 According to MSDN , culture specific values are inherently unstable. 根据MSDN ,文化特定值本质上是不稳定的。 I think that what you see is more of an OS thing, could change between Windows Updates. 我认为你看到的更多是操作系统的东西,可能会在Windows更新之间发生变化。 If you need something stable, in unit test for example, invariant or custom culture is the best bet. 如果您需要稳定的东西,例如在单元测试中,不变或定制文化是最好的选择。

NumberFormatInfo and dynamic data NumberFormatInfo和动态数据

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. 用于格式化由NumberFormatInfo类提供的数值的特定于文化的数据是动态的,就像CultureInfo类提供的文化数据一样。 You should not make any assumptions about the stability of values for NumberFormatInfo objects that are associated with particular CultureInfo objects. 您不应对与特定CultureInfo对象关联的NumberFormatInfo对象的值的稳定性做出任何假设。 Only the data provided by the invariant culture and its associated NumberFormatInfo object is stable. 只有不变文化及其关联的NumberFormatInfo对象提供的数据才是稳定的。 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. 发生这种情况时,Windows Update包含对特定区域性的NumberFormatInfo属性值的更改。

  • Replacement cultures . 替代文化 The CultureAndRegionInfoBuilder class can be used to replace the data of an existing culture. CultureAndRegionInfoBuilder类可用于替换现有文化的数据。

  • Cascading changes to property values . 级联更改属性值 A number of culture-related properties can change at run time, which, in turn, causes NumberFormatInfo data to change. 许多与文化相关的属性可以在运行时更改,这反过来会导致NumberFormatInfo数据发生更改。 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. 发生这种情况时,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对象的属性。

Check Control Panel > Clock, Language, and Region > Change date, time, or number formats > Additional Settings 检查控制面板>时钟,语言和区域>更改日期,时间或数字格式>其他设置

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM