Parse a Number from Exponential Notation

Jimbo picture Jimbo · Oct 7, 2010 · Viewed 81.4k times · Source

I need to parse the string "1.2345E-02" (a number expressed in exponential notation) to a decimal data type, but Decimal.Parse("1.2345E-02") simply throws an error

Answer

Hans Passant picture Hans Passant · Oct 7, 2010

It is a floating point number, you have to tell it that:

decimal d = Decimal.Parse("1.2345E-02", System.Globalization.NumberStyles.Float);