0

I have a strange problem. When my custom formatted Hex value is tested with double.Tryparse it returns inconsistent results

For example

if (double.TryParse(dblValue, NumberStyles.Float, CultureInfo.InvariantCulture, out double x))

If the dblValue = "0E-63" the above statement returns true and if dblValue = "0E-5B" it returns false I expect both of these custom formatted hex values to return false in TryParse, so that my code handles them as not a number. What am I missing here.

other than this double and integers are working as expected.

3
  • 2
    0E-63 is a valid decimal number in scientific format, 0E-5B is not. Thats why it parses the first one but not the second one. Commented Feb 7, 2023 at 16:10
  • 1
    If you use NumberStyles.Number then trying to parse scientific notation would fail, but it's not clear if that's the intent here or not since hex values are typically parsed to integer types and do not contain dashes. Is the intent to parse the base and exponent as separate hex numbers? Commented Feb 7, 2023 at 16:13
  • Thank you for the answers. Its just a custom formatted Hex value for display purposes and I want the tryparse to fail here. NumberStyles.Number did the job for me. Commented Feb 7, 2023 at 16:25

1 Answer 1

1

0E-63 here is not hex - it is 0 x (10 to the power of -63) - in the same way that 1E-03 parses as 0.001 i.e. 1 x (10 to the power of -3).

This API does not parse hex.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.