Search code examples
c#windows-7windows-8

float parse are different on Windows 7 or 8?


I tested my program on Windows 7 today. It did not work, i found the error.

Following situation:

I converted a string into a float. Windows 8: float.Parse (String.Replace(".", ","))

But on Windows 7, I have to do the opposite directly to not have a crash.

Windows 7: float.Parse(String.Replace (",", "."))

Windows 7 float = 50.00

Windows 8 float = 50,50

Why is that?

Do you know good ways to solve this?


Solution

  • It's nothing to do with Windows 7 or 8 but your regional/localization settings. If you want to be able to always parse with '.' you can specify System.Globalization.CultureInfo.InvariantCulture as the second argument to most parsing functions.