Skip to content

[Form] Update rounding mode defintion integer type #14750

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions reference/forms/types/integer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,42 @@ Field Options
``rounding_mode``
~~~~~~~~~~~~~~~~~

**type**: ``integer`` **default**: ``IntegerToLocalizedStringTransformer::ROUND_DOWN``
**type**: ``integer`` **default**: ``\NumberFormatter::ROUND_HALFUP``

By default, if the user enters a non-integer number, it will be rounded
down. There are several other rounding methods and each is a constant
on the :class:`Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\IntegerToLocalizedStringTransformer`:
By default, if the users enters a non-integer number, it will be rounded
down. You have several configurable options for that rounding. Each option
is a constant on the :phpclass:`NumberFormatter` class:

* ``IntegerToLocalizedStringTransformer::ROUND_DOWN`` Round towards zero.
* ``\NumberFormatter::ROUND_DOWN`` Round towards zero. It
rounds ``1.4`` to ``1`` and ``-1.4`` to ``-1``.

* ``IntegerToLocalizedStringTransformer::ROUND_FLOOR`` Round towards negative
infinity.
* ``\NumberFormatter::ROUND_FLOOR`` Round towards negative
infinity. It rounds ``1.4`` to ``1`` and ``-1.4`` to ``-2``.

* ``IntegerToLocalizedStringTransformer::ROUND_UP`` Round away from zero.
* ``\NumberFormatter::ROUND_UP`` Round away from zero. It
rounds ``1.4`` to ``2`` and ``-1.4`` to ``-2``.

* ``IntegerToLocalizedStringTransformer::ROUND_CEILING`` Round towards
positive infinity.
* ``\NumberFormatter::ROUND_CEILING`` Round towards positive
infinity. It rounds ``1.4`` to ``2`` and ``-1.4`` to ``-1``.

* ``IntegerToLocalizedStringTransformer::ROUND_HALF_DOWN`` Round towards the
"nearest neighbor". If both neighbors are equidistant, round down.
* ``\NumberFormatter::ROUND_HALFDOWN`` Round towards the
"nearest neighbor". If both neighbors are equidistant, round down. It rounds
``2.5`` and ``1.6`` to ``2``, ``1.5`` and ``1.4`` to ``1``.

* ``IntegerToLocalizedStringTransformer::ROUND_HALF_EVEN`` Round towards the
"nearest neighbor". If both neighbors are equidistant, round towards the
even neighbor.
* ``\NumberFormatter::ROUND_HALFEVEN`` Round towards the
"nearest neighbor". If both neighbors are equidistant, round towards the even
neighbor. It rounds ``2.5``, ``1.6`` and ``1.5`` to ``2`` and ``1.4`` to ``1``.

* ``\NumberFormatter::ROUND_HALFUP`` Round towards the
"nearest neighbor". If both neighbors are equidistant, round up. It rounds
``2.5`` to ``3``, ``1.6`` and ``1.5`` to ``2`` and ``1.4`` to ``1``.

.. deprecated:: 5.1

In Symfony versions prior to 5.1, these constants were also defined as aliases
in the :class:`Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\IntegerToLocalizedStringTransformer`
class, but they are now deprecated in favor of the :phpclass:`NumberFormatter` constants.

* ``IntegerToLocalizedStringTransformer::ROUND_HALF_UP`` Round towards the
"nearest neighbor". If both neighbors are equidistant, round up.

Overridden Options
------------------
Expand Down