-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Conversation
} | ||
if (tp == typeof(double)) | ||
{ | ||
return double.Parse(text, _config.NumberParseCulture); | ||
return double.Parse(text, _culture); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
No description provided.