Not logged in - Login

How to convert scientific notation string to decimal

How to convert this scientific notation to decimal?

Convert strings that are in scientific notation to decimals. The following do NOT work:

// using the Convert class:
decimal t1 = Convert.ToDecimal("2.09550901805872E-05");   
// using Decimal.Parse:
decimal t2 = Decimal.Parse("2.09550901805872E-05");

To allow for scientific notation, some flags must be added.

// This does work:
decimal t2 = Decimal.Parse("2.09550901805872E-05", 
   NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint);

// allow for any culture:
decimal t2 = Decimal.Parse("2.09550901805872E-05", 
   NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint,
   CultureInfo.InvariantCulture);

// it may be easier to use the 'Any' number style
decimal t2 = Decimal.Parse("2.09550901805872E-05", 
   NumberStyles.Any, 
   CultureInfo.InvariantCulture);