Skip to content

[Form] ability to set rounding strategy for MoneyType #26767

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

Merged
merged 1 commit into from
Apr 4, 2018

Conversation

syastrebov
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets no
License MIT
Doc PR symfony/symfony-docs#9543

Added rounding_mode to the MoneyType to be possible to change rounding strategy for money values. For now it's just ROUND_HALF_UP but it's good to have ROUND_DOWN as well. E.g. to transform 15.999 to 15.99 instead of 15.1.

@syastrebov syastrebov changed the title ability to set rounding strategy ability to set rounding strategy for MoneyType Apr 3, 2018
@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Apr 3, 2018
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 3, 2018

would you mind adding some tests please?
(and congrats and thank you for your first PR :) )

@syastrebov syastrebov changed the title ability to set rounding strategy for MoneyType [Form] ability to set rounding strategy for MoneyType Apr 3, 2018
@syastrebov syastrebov force-pushed the set-money-rounding-mode branch from e63a499 to f3b1424 Compare April 4, 2018 11:15
@syastrebov
Copy link
Contributor Author

@nicolas-grekas You're welcome :) Added tests for the changes, please take a look.

@fabpot
Copy link
Member

fabpot commented Apr 4, 2018

Thank you @syastrebov.

@fabpot fabpot merged commit f3b1424 into symfony:master Apr 4, 2018
fabpot added a commit that referenced this pull request Apr 4, 2018
…(syastrebov)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[Form] ability to set rounding strategy for MoneyType

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | no
| License       | MIT
| Doc PR        | symfony/symfony-docs#9543

Added `rounding_mode` to the `MoneyType` to be possible to change rounding strategy for money values. For now it's just `ROUND_HALF_UP` but it's good to have `ROUND_DOWN` as well. E.g. to transform `15.999` to `15.99` instead of `15.1`.

Commits
-------

f3b1424 rounding_mode for money type
@syastrebov syastrebov deleted the set-money-rounding-mode branch April 5, 2018 08:20
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Apr 16, 2018
This PR was merged into the master branch.

Discussion
----------

rounding_mode for money type

Added docs for symfony/symfony#26767

Commits
-------

819d0a6 rounding_mode for money type
@fabpot fabpot mentioned this pull request May 7, 2018
'divisor' => 1,
'currency' => 'EUR',
'compound' => false,
));

$resolver->setAllowedValues('rounding_mode', array(
NumberToLocalizedStringTransformer::ROUND_FLOOR,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why using NumberToLocalizedStringTransformer and not NumberFormatter here ? Adding a dependency to a transformer without using it doesn't seem right.

Copy link
Member

Choose a reason for hiding this comment

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

NumberToLocalizedStringTransformer is the parent class of the MoneyToLocalizedStringTransformer which is used by this form type and that is configured through these options.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then why not MoneyToLocalizedStringTransformer::ROUND_FLOOR ?

@erlangparasu
Copy link

@syastrebov how to round-up by 100, sir? round-down by 100?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants