如何确保在WinForms中使用localculture作为接口而不是浮点数值?

问题描述:

我在俄罗斯系统上有一个WinForms应用程序。由于多种原因,我更喜欢使用InvariantCulture(这是英文)的浮动值格式。如何确保在WinForms中使用localculture作为接口而不是浮点数值?

以下在互联网中找到解决方案,我已将InvariantCulture设置为应用程序的默认文化。但是,因此,表单的本地化版本(使用俄文文本)从不加载。

如何确保俄语文本的表单自动加载到俄语机器上,但对于浮点值字符串转换InvariantCulture行为是否被使用?

+0

为俄罗斯区域设置,然后更改数字格式。 – Sinatr

+0

添加该答案作为回答 – Srv19

您可以为特定的文化创建后改变的CultureInfo任何财产,如:

// create culture with default values for russian 
var culture = new CultureInfo("ru-RU"); 
// change number format 
culture.NumberFormat = new NumberFormatInfo { NumberDecimalSeparator = "." }; 
// set culture 
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = culture; 

之后,你不需要解析/格式化指定文化:

var test = double.Parse("1.234"); // would throw without changing NumberFormat 
MessageBox.Show(test.ToString()); // output: 1.234 
+0

谢谢!这种可能性超过了我 – Srv19