It's just behaving as documented. From Double.Parse
:
The s parameter is interpreted using a combination of the NumberStyles.Float and NumberStyles.AllowThousands flags.
Note that NumberStyles.Float
includes NumberStyles.AllowExponent
.
From Decimal.Parse
:
Parameter s is interpreted using the NumberStyles.Number style.
NumberStyles.Number
does not include NumberStyles.AllowExponent
.
I can't reproduce your bizarre stack traces which appear to show the same call failing just after it's worked:
Decimal.Parse("1e-2")
always fails for me
Decimal.Parse("1e-2", NumberStyles.Float)
always works for me
Double.Parse("1e-2")
always works for me
Double.Parse("1e-2", NumberStyles.Float)
always works for me
As for why the "default" number style differs between the two - I suspect it's because double
values typically are used in scientific scenarios where exponent-based representations are common, but decimal
values typically aren't.