Whenever I try to parse the String
"-30.00" to a float, I'll get -3000.0 as a result.
Can someone explain to me why that happens? What can I do to avoid such a problem?
Here's the code:
Note: splitMin
is "MIN(-30.00)"
and splitMax
is "MAX(70.00)"
in the beginning. This is why I had to remove a few characters.
splitMin = splitMin.Remove(0, 4);
splitMax = splitMax.Remove(0, 4);
splitMin = splitMin.Remove(splitMin.Length - 1, 1);
splitMax = splitMax.Remove(splitMax.Length - 1, 1);
float min = float.Parse(splitMin);
float max = float.Parse(splitMax);
I've just checked with
Console.WriteLine(float.Parse("30,00"));
And this does return 3000 for me, so I'd imagine your culture settings are in play here.
Try
float.Parse(splitMin, CultureInfo.InvariantCulture)