Convert from scientific notation string to float in C#
Solution 1:
Double.Parse("1.234567E-06", System.Globalization.NumberStyles.Float);
Solution 2:
Also consider using
Double.TryParse("1.234567E-06", System.Globalization.NumberStyles.Float, out MyFloat);
This will ensure that MyFloat
is set to value 0 if, for whatever reason, the conversion could not be performed. Or you could wrap the Double.Parse()
example in a Try..Catch
block and set MyFloat
to a value of your choosing when an exception is detected.