Skip to content

Deprecated the NumberToLocalizedStringTransformer constants #13654

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
May 12, 2020
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
28 changes: 17 additions & 11 deletions reference/forms/types/options/rounding_mode.rst.inc
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
rounding_mode
~~~~~~~~~~~~~

**type**: ``integer`` **default**: ``NumberToLocalizedStringTransformer::ROUND_HALF_UP``
**type**: ``integer`` **default**: ``\NumberFormatter::ROUND_HALFUP``

If a submitted number needs to be rounded (based on the `scale`_
option), you have several configurable options for that rounding. Each
option is a constant on the :class:`Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\NumberToLocalizedStringTransformer`:
If a submitted number needs to be rounded (based on the `scale`_ option), you
have several configurable options for that rounding. Each option is a constant
on the ``\NumberFormatter`` class:
Copy link
Member

Choose a reason for hiding this comment

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

What about doing :phpclass:`NumberFormatter` here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Done in af24efa


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

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

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

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

* ``NumberToLocalizedStringTransformer::ROUND_HALF_DOWN`` Round towards the
* ``\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``.

* ``NumberToLocalizedStringTransformer::ROUND_HALF_EVEN`` Round towards the
* ``\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``.

* ``NumberToLocalizedStringTransformer::ROUND_HALF_UP`` Round towards the
* ``\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\\NumberToLocalizedStringTransformer`
class, but they are now deprecated in favor of the ``\NumberFormatter`` constants.