-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
NumberType does not apply rouding when scale is not defined #20134
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
Comments
As a side-note, this doesn't seem to be linked to the Here is a short reproducer: $formatter = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
var_dump($formatter->format(485.3485)); // Outputs: string(7) "485.348" |
I'm starting to think that it might not be a documentation problem, but rather a bug in In Also, But because In any case, I'm kind of confused. Many thanks. |
I'm a bit lost here too. Let's see if someone can take a look here and give us some clue. Thanks! |
I found time to run a few more tests and I could create a reproducer that illustrates better the behavior I'm experiencing, and I really think it might be a bug now. Here is the issue (with the reproducer): symfony/symfony#58204 Not sure if this ticket should stay open, then. |
Hi :)
I may be wrong, but documentation (Symfony 5.x) says that
NumberType
's optionrounding_mode
defaults to\NumberFormatter::ROUND_HALFUP
: https://symfony.com/doc/5.x/reference/forms/types/number.html#rounding-modeIn my project, one of my form's fields is a
NumberType
, with norounding_mode
norscale
configured:But because of how
\Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer::getNumberFormatter
has been implemented, I think the documentation is not accurate:As shown above, the number formatter is not configured with any rounding when no scale is defined (even if one is configured in the form I reckon). Because of that, in our project (with French locale), the effective rounding mode used is
\NumberFormatter::ROUND_HALFEVEN
(and scale seems to default to3
). Instead of the advertised\NumberFormatter::ROUND_HALFUP
.This gives us an unexpected and weird behavior when users type in numbers like
485,3485
, as it gets rounded to485,348
instead of485,349
.In all honesty, I'm not sure if this is a documentation issue, a bug in
NumberToLocalizedStringTransformer::getNumberFormatter
or if I'm missing something?Thanks for your insights :)
The text was updated successfully, but these errors were encountered: