[英]CultureInfo result in visual studio is different between windows 8 and windows 10
I found that CultureInfo class returns information such as number format which is different when executing in windows 8.1 and 10. I created a simple console application to conform which is given below. 我发现CultureInfo类返回的信息(例如数字格式)在Windows 8.1和10中执行时会有所不同。我创建了一个简单的控制台应用程序,以使其符合以下要求。 In windows 8.1 the result of conversion is 2235. But in windows 10 the result is 0. I am using visual studio 2013 in both environment.
在Windows 8.1中,转换的结果是2235。但是在Windows 10中,结果是0。我在两种环境中都使用Visual Studio 2013。
CultureInfo cultureInfo = new CultureInfo(3079);
System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
string value = "2.235";
decimal test;
decimal.TryParse(value, NumberStyles.Any, cultureInfo, out test);
Please let me know if you need any further information to give a clear picture. 如果您需要其他任何信息以清晰呈现图片,请告诉我。
Regards Prathap 关于Prathap
This 这个
CultureInfo cultureInfo = new CultureInfo(3079);
is the same as 是相同的
CultureInfo cultureInfo = new CultureInfo("de-AT");
It's the austrian culture. 这是奥地利文化。 They use comma as decimal separator but space as thousands separator(as opposed to germans who use
.
for thousands). 他们使用逗号作为小数点分隔符,但使用空格作为千位分隔符(与德国人使用
.
代表千位分隔符相反)。
So this works (appended ,99
for clarity, you can remove it): 因此可以正常工作(为清晰起见,添加为
,99
,可以将其删除):
string value = "2 235,99";
bool valid = decimal.TryParse(value, NumberStyles.Any, new CultureInfo("de-AT"), out test);
But this format not: string value = "2.235,99"
但是这种格式不是:
string value = "2.235,99"
So it has nothing to do with your OS version. 因此,它与您的操作系统版本无关。
Note that you should always store the result of TryParse
( bool
) in a variable or use an if...else
instead of using the returned out
value to determine whether it could be parsed or not. 需要注意的是,你应该的结果总是存储
TryParse
( bool
)在一个变量或使用if...else
而不是使用返回out
值,以确定它是否能够被解析与否。 Even 0
could be a valid value. 甚至
0
可能是有效值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.