-
Notifications
You must be signed in to change notification settings - Fork 603
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
Breaking changes in number parsing after 1.2.0 #675
Comments
Hello @eric-brechemier, thanks for bringing these points to our attention. On version <1.2.0, the number parser had significant bugs as you demonstrated above, also see #292 and #353. All these have been fixed in The parser now works correctly. All the
Assume The implemented function parseNumerberOrPercentage(numberOrPercentageString) {
return globalize.parseNumber(numberOrPercentageString) ||
globalize.parseNumber(numberOrPercentageString, {style: "percent"});
} Note that on date parser, we chose to go with the same specific style/patterns instead of trying to guess several patterns for the develop.
I can't think of any, if you find please just let us know.
Not true, the real value of Globalize is to deal with the i18n tough problems, not to avoid you do the helper above (that is too obvious). The real problem parsing a number goes in places like parsing a different numbering systems (like arabic), loose matchings like #292, or even making sure you don't parse a wrong currency or a wrong percentage value.
This should indeed return a |
I closed this issue, because I don't think this is a bug. I still think it was very important you raised these points, because it shows we might do a better job explaining them. Do you have a suggestion how we could improve that? In our documentation, we have https://github.com/globalizejs/globalize/blob/master/doc/api/number/number-parser.md. Thanks again |
Hi Rafael, OK, fair enough -- if that's how it's supposed to work then I can accept that. I hadn't thought to parse the same input twice both with and without the percent flag. Good idea! That gets around the need to perform any pre-parsing by the calling code, so you can disregard my comments regarding that. Though careful -- the example you gave fails for input "0" ;-). Nevertheless the general idea would work. As far as improving the documentation, my only suggestion would be to make it a bit clearer that the Thanks for you time and quick response. |
Hi, thanks for your understanding.
That's what we have considering that
It would be awesome if you could send a PR with your suggested improvement. :) Thanks |
In the following code:
if
You're right, don't know how I missed that. |
True 🙈, thanks 😄 |
Hello,
After upgrading to 1.2.x, the behavior of number parsing has changed significantly, and seems somewhat broken:
Version 1.1.2:
Version 1.2.0:
So, parsing currency is no longer possible at all. Parsing percent now only works if
style: "percent"
is specified, in which case it will only recognize percent input. I'm not sure if this was the intended use of this flag all along, but it makes the API significantly less useful. If I want to accept either "0.75" or "75%" as valid input to mean 0.75, then I must do my own pre-flight check to see whether or not it's a percent. Forcing the calling code to make this type of check makes it likely that it will fail for some combination of input and locale, and defeats the purpose of using an API like Globalize in the first place. The old behavior of this flag didn't seem quite right either though, since it seemingly had no effect at all.The text was updated successfully, but these errors were encountered: