8000 [Intl] Added round support for ROUND_CEILING, ROUND_FLOOR, ROUND_DOWN, ROUND_UP by pamil · Pull Request #9895 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
wants to merge 5 commits into from
Closed

[Intl] Added round support for ROUND_CEILING, ROUND_FLOOR, ROUND_DOWN, ROUND_UP #9895

wants to merge 5 commits into from

Conversation

pamil
Copy link
Contributor
@pamil pamil commented Dec 30, 2013
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.

$roundingModeAttribute = $this->getAttribute(self::ROUNDING_MODE);
if (isset(self::$phpRoundingMap[$roundingModeAttribute])) {
$roundingMode = self::$phpRoundingMap[$this->getAttribute(self::ROUNDING_MODE)];
$value = round($value, $precision, $roundingMode);
Copy link
Member

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]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@fabpot
Copy link
Member
fabpot commented Dec 30, 2013

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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@pamil
Copy link
Contributor Author
pamil commented Dec 30, 2013

I'm wondering if we could extract NumberFormatter::round() functionality to public-available method. There's Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer::round() with the same functionality. We could also use this method in Twig_Extension_Core::twig_round() to provide more rounding modes. The only downside I see is dependency with library containing this rounding method.

@fabpot
Copy link
Member
fabpot commented Dec 30, 2013

I prefer duplicate code in this case

fabpot added a commit that referenced this pull request Dec 31, 2013
…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
@fabpot fabpot closed this Dec 31, 2013
@pamil pamil deleted the issue9838-from-sf24 branch January 7, 2014 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0