Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NumberParsing for double with exponent #532

Merged
merged 3 commits into from
Jul 12, 2021
Merged

Fix NumberParsing for double with exponent #532

merged 3 commits into from
Jul 12, 2021

Conversation

StefH
Copy link
Collaborator

@StefH StefH commented Jul 11, 2021

No description provided.

@StefH StefH added the bug label Jul 11, 2021
@StefH StefH self-assigned this Jul 11, 2021
@StefH StefH changed the title Stef numberstyles Fix NumberParsing dor double with exponent Jul 11, 2021
@StefH StefH changed the title Fix NumberParsing dor double with exponent Fix NumberParsing for double with exponent Jul 11, 2021
}
if (tp == typeof(double))
{
return double.Parse(text, _config.NumberParseCulture);
return double.Parse(text, _culture);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I think the default will work great for us. FWIW, the default value seems to be NumberStyles.Float | NumberStyles.AllowThousands. According to the somewhat confusing NumberStyles docs, this actually does exclude one flag that was enabled prior to this change, which was NumberStyles.AllowTrailingSign.

This flag is really strange, it lets me specify the sign after the number like in this fiddle. I haven't seen any actual use cases of this in the wild, and I don't know if the parser even supports it. I definitely don't need trailing signs, just wanting to make sure that we aren't regressing this edge case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried it, and it looks like trailing signs are already rejected elsewhere in the parser. So, this isn't a regression at all, we can ignore the trailing sign flag 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

new object[] { null, "1d", 1d },
new object[] { null, "-42d", -42d },
new object[] { null, "3.215d", 3.215d },
new object[] { null, "1.2345E-4", 0.00012345d },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are looking great. We saw a few cases where there was a lowercase e in the exponent. double.Parse handles this with no issue, but it may be worth including a test for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did add this test.

Copy link
Contributor

@alexweav alexweav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@StefH
Copy link
Collaborator Author

StefH commented Jul 12, 2021

#531

@StefH StefH merged commit bd3fe7c into master Jul 12, 2021
@StefH StefH deleted the stef_numberstyles branch July 12, 2021 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants