I have a string "3.0E-4"
, it is supposed to be a decimal number.
Please advise how to convert to a decimal.
You can use AllowExponent
and AllowDecimalPoint
styles combination with decimal.Parse
method like;
var result = decimal.Parse("3.0E-4",
NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint,
CultureInfo.InvariantCulture);
Try this:
decimal x = Decimal.Parse("3.0E-4", NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint);
or like
decimal x = Decimal.Parse("3.0E-4", NumberStyles.Any, CultureInfo.InvariantCulture);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With