Conversion to double causing trouble in german version

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.

Hi @tobias.stoltmann,

You might see if RhinoMath.TryParseNumber works better.

– Dale

Dear @tobias.stoltmann

what exactly do you want to achieve on the english and german machine ?
what input should be allowed ?
using thousand-separator and decimal-separator the expected input would look like this for the same 1234.56:

string stren = "1,234.56"; // english
string strde = "1.234,56"; // german

(a) should both inputs be possible on both machines ?
→ you have to dig a bit deeper and maybe do some custom filtering
(b) or should both machines only expect the english format ?
CultureInfo.InvariantCulture should do it
(c) or should both machines only expect their cultureinfo ?
→ there is also CultureInfo.CurrentCulture

looking forward to read your results / experiences, also about RhinoMath.TryParseNumber

kind regards -tom

( and to keep topics linked - there is a topic / wish, that rhino should accept dot and comma as decimal separator - this will make situations like this even worse )

@dale it turned out that the problem was somewhere else.
I implemented this way of parsing though, as it seems quite comfortable to me. So, @Tom_P this works fine! :slight_smile: