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. 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.
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
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):
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"
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. Even 0
could be a valid value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.