Search code examples
c#visual-studio-2010doubletype-conversionexponential

Convert 7.346000E-001 or 7.3460000E+000 to Double


I'm trying to convert a string value to Double but I sill get error saying that the format is incorrect.

My Strings are represented like this : 7.346000E-001, 7.3460000E+000

Is there another way to convert them or I need to truncate the string into two parts and do the calculation by myself to get the real value ?


Solution

  • Try CultureInfo.InvariantCulture with double.parse

    System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); // just to simulate french culture
    double d = double.Parse("7.3460000E-001",CultureInfo.InvariantCulture);
    Console.Write(d);