简体   繁体   中英

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM