[Form] NumberType: Fix parsing of numbers in exponential notation with negative exponent#57861
Merged
Merged
Conversation
|
Hey! Thanks for your PR. You are targeting branch "7.1" but it seems your PR description refers to branch "5.4, 6.4, 7.0, and 7.1 for bug fixes". Cheers! Carsonbot |
Member
|
Is 5.4 not affected by this? Also we need some tests to prevent regressions. |
Contributor
Author
|
@xabbuh Yes Symfony 5.4 (and all other currently supported versions) are affected by this bug, as the relevant code parts were not changed for a while. I also added some tests for the parsing of numbers in e-notation, which was not covered by tests before. These should also prevent regression of this issue. |
…h negative exponent
4eeeb4c to
62c70bd
Compare
Member
|
Thank you @jbtronics. |
This was referenced Aug 30, 2024
Merged
Merged
Merged
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, when inputting a string like "1E-3" into a NumberType leads incorrectly to a result of "0". The correct result would be "0.001", which is also the result, when inputting "1.0E-3".
This is caused by
NumberToLocalizedStringTransformer, which assumes that the result must be a integer, if the string does not contain the decimal separator. However, this behavior is incorrect, if the string is in exponential notation with negative exponent.The NumberFormatter can correctly parse this format, but it needs to be told that the result should be a double (otherwise its gets incorrectly rounded to 0)
To fix this behavior, I added a check for the negative exponential format, which then results in a double result.