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
Large number is truncated by NumberToLocalizedStringTransformer #26795
Labels
Comments
for the doc issue, please report it to https://github.com/symfony/symfony-docs (or even better, open a PR to fix it) |
This was referenced Apr 4, 2018
Done. |
Second issue was already reported in #26734, incl. doc PR |
Thanks @ostrolucky, so the doc stuff is now irrelevant in this issue. The integer "rounding" still is though. |
Looks like this was introduced in 2.8.5 |
Thank you for reporting. This should be fixed by #30063. |
nicolas-grekas
added a commit
that referenced
this issue
Feb 8, 2019
… (xabbuh) This PR was merged into the 3.4 branch. Discussion ---------- [Form] don't lose int precision with not needed type casts | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26795 | License | MIT | Doc PR | Commits ------- 72136f1 don't lose int precision with not needed type casts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context
I have a form based off of an entity that has a big int field:
MySQL is the database engine and when entering manual queries it works perfectly.
The form is built with this type:
Note that I also tried the one argument
add
method with exactly the same result.The issue
Now when I submit the form with an input of
201803221011791
it is saved as201803221011790
.Analysis
I have debugged the code to this portion of
NumberToLocalizedStringTransformer:184
where the data is cast as a float:This looks like a float but it seems that PHP handles that as a double internally:
The precision is not lost yet:
So later on in the
round
method line 244, it is parsed as a string (scale
is0
so theroundingCoef
is1
):So from now on
number
is2
:Later on line 259 (
roundingMode
isROUND_DOWN
):So basically we are doing this:
Which as you can see causes the last digit to be wrong.
Additional remark
The
IntegerType
usesIntegerToLocalizedStringTransformer
, but the constructor erases thescale
option, and calls the parent constructor withscale
=0
hard-coded:The PHPDoc mentions the scale parameter is ignored, but this is not documented here: https://symfony.com/doc/3.4/reference/forms/types/number.html#scale
The text was updated successfully, but these errors were encountered: