Search code examples
c#type-conversionformatexception

Input string was not in a correct format on Convert.ToDouble("Infinity")


Why would the following fail with a System.FormatException on 64-bit Windows 10, but runs fine on 32-bit Windows 7? Both machines have .NET Framework 4.6.1 installed.

Convert.ToDouble("Infinity");

I have searched and cannot find an answer to this.


Solution

  • The string used for Infinity is culture specific and may have even had different values between Win 7 & 10 (can't confirm that at the moment).

    Try using the constant instead of hard coding a string:

    Convert.ToDouble(NumberFormatInfo.PositiveInfinitySymbol);