double.TryParse在荷兰 [英] double.TryParse in dutch
问题描述
Web服务器在荷兰语(比利时)运行
Web server running in Dutch(Belgium)
double output;
double.TryParse(txtTextbox1.Text, out output);
这是将文本转换在荷兰环境翻番的好办法?比方说,输入 24.45 而不是 24,45
Is this a good way to convert text to double in dutch environment? Let's say the input is "24.45" instead of "24,45"
推荐答案
如果您想使用荷兰语(比利时)号格式:
If you want to use the Dutch (Belgium) number format:
double output;
double.TryParse("24,45", NumberStyles.Any, CultureInfo.GetCultureInfo("nl-BE"), out output);
或者用美国的数字格式:
Or to use the US number format:
double output;
double.TryParse("24.45", NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out output);
如果你试图解析24.45与荷兰文化集,你会得到2445 同样,如果你试图解析24,45与美国的文化,你会得到2445。如果你想解析失败如果使用了错误的小数点,更改NumberStyles.Any排除标志: NumberStyles.AllowThousands
:
If you attempt to parse "24.45" with a Dutch culture set, you'll get back "2445", similarly, if you attempt to parse "24,45" with a US culture, you'll get "2445". If you want the parse to fail if the wrong decimal point is used, change NumberStyles.Any to exclude the flag: NumberStyles.AllowThousands
:
double output;
if (double.TryParse("24.45", NumberStyles.Any ^ NumberStyles.AllowThousands, CultureInfo.GetCultureInfo("nl-BE"), out output))
如果您的整个应用程序在荷兰,你应该在全球范围改变你的CultureInfo - 的这里是如何做到这一点在的WinForms 和是如何做到这一点在ASP 。.NET
If your entire application is in Dutch, you should change your cultureinfo globally - here's how to do it in WinForms and here's how to do it in ASP.NET.
在您使用的是全局设置的CultureInfo,您可以更改上面的代码:
Once you're using a globally set CultureInfo, you can change the above code to:
double output;
double.TryParse("24.45", NumberStyles.Any, CultureInfo.CurrentCulture, out output);
这篇关于double.TryParse在荷兰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!