Hi there,
My OS and all software is in english.
I am experiencing a problem with a plugin I am writing on the german machine of a colleague of mine (on which software and OS in german).
I am trying to parse a string (e.g. 1.23) into a double with the following code.
On my machine it works perfectly fine, on my colleague’s one it does not do anything at all.
(I am totally aware that it could be more elegant in terms of the if/else statements)
public static double TextToDouble(string str)
{
double value;
if (str.Contains(","))
Double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out value);
else
{
if (str.Contains("."))
Double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out value);
else
Double.TryParse(str, out value);
}
return value;
}
My question is: Is the way I try to parse the string totally wrong, meaning should I use some other methods?
I assume that a string “1.23” will be converted to a double 123
on his machine, right?
As I am clueless how to work around this any help is highly appreciated.
Thanks,
T.