'Why does AllowExponent makes Decimal.Parse fail to parse normal numbers?

I tried these

    Dim a = Decimal.Parse("0.00001", System.Globalization.NumberStyles.Any)
    Dim c = Decimal.Parse("0.00001")
    Dim cb = Decimal.Parse("0.00001", System.Globalization.NumberStyles.AllowExponent)

The first code works.

The second line works.

The third line doesn't work.

It seems that if I do not mention the numberstyles, the numberstyles default to something. Default to what?

It basically allow parsing normal number (".00001"). However, that ability is turned off if System.Globalization.NumberStyles.AllowExponent is specified as parameter.

Why is this happening?

What is the default value of NumberStyles if we use the normal overload of Decimal.parse, without additional parameters?



Solution 1:[1]

I just want to add that per Parsing decimal in scientific notation

System.Globalization.NumberStyles.AllowExponent

doesn't allow putting decimals.

It's probably unituitive.

Hence,

cb = Decimal.Parse("0.00001", System.Globalization.NumberStyles.AllowExponent)

will throw error because the parser cannot parse .

I have no idea why it's designed that way. So how are we going to parse 4.5e10, for example.

You need other options. AllowExponent seems to do exactly that. Allow Exponent and that's it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1