-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Intl] Added round support for ROUND_CEILING, ROUND_FLOOR, ROUND_DOWN, ROUND_UP #9895
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
Conversation
$roundingModeAttribute = $this->getAttribute(self::ROUNDING_MODE); | ||
if (isset(self::$phpRoundingMap[$roundingModeAttribute])) { | ||
$roundingMode = self::$phpRoundingMap[$this->getAttribute(self::ROUNDING_MODE)]; | ||
$value = round($value, $precision, $roundingMode); |
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.
Those 2 lines can be replaced with $value = round($value, $precision, self::$phpRoundingMap[$roundingModeAttribute]);
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.
Done.
Looks good to me, can you add some unit tests? |
'ROUND_CEILING' => self::ROUND_CEILING, | ||
'ROUND_FLOOR' => self::ROUND_FLOOR, | ||
'ROUND_DOWN' => self::ROUND_DOWN, | ||
'ROUND_UP' => self::ROUND_UP |
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.
Please add the trailing comma so that we don't have unneeded diffs on this line when we need to add another one after that
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.
Done.
I'm wondering if we could extract |
I prefer duplicate code in this case |
…ROUND_DOWN, ROUND_UP (pamil) This PR was squashed before being merged into the 2.4 branch (closes #9895). Discussion ---------- [Intl] Added round support for ROUND_CEILING, ROUND_FLOOR, ROUND_DOWN, ROUND_UP | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no, actually it fixes some | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9838 | License | MIT | Doc PR | Adds support for 4 unsupported rounding modes (ROUND_CEILING, ROUND_FLOOR, ROUND_DOWN, ROUND_UP) in `NumberFormatter` from `Intl` component, so that `Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer` won't throw exception if `lib-intl` is not installed. Commits ------- f5fee9a [Intl] Added round support for ROUND_CEILING, ROUND_FLOOR, ROUND_DOWN, ROUND_UP
Adds support for 4 unsupported rounding modes (ROUND_CEILING, ROUND_FLOOR, ROUND_DOWN, ROUND_UP) in
NumberFormatter
fromIntl
component, so thatSymfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer
won't throw exception iflib-intl
is not installed.