user2132291
user2132291

Reputation: 9

Convert or parse string to decimal

I have this string: "7.0000000000000007E-2" (data.InnerText). I use the following code but this gave me the error: "Input string was not in a correct format.".

decimal value = Decimal.Parse(data.InnerText, CultureInfo.InvariantCulture);

I only need the number rounded on 2 decimals.

Upvotes: 1

Views: 1729

Answers (1)

Gauthier Boaglio
Gauthier Boaglio

Reputation: 10272

If your culture uses . as the decimal separator :

double d = double.Parse("7.0000000000000007E-02");

Or try that way :

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

Upvotes: 2

Related Questions