Skip to content

Commit cbc9f85

Browse files
committed
minor symfony#14750 Update rounding mode defintion integer type (MrYamous)
This PR was squashed before being merged into the 5.1 branch. Discussion ---------- Update rounding mode defintion integer type The rounding_mode definition for IntegerType wasn't up to date after depreciation of `IntegerToLocalizedStringTransformer::ROUND_*` constants Commits ------- 3a7985f Update rounding mode defintion integer type
2 parents 65ecb85 + 3a7985f commit cbc9f85

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

reference/forms/types/integer.rst

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,42 @@ Field Options
5555
``rounding_mode``
5656
~~~~~~~~~~~~~~~~~
5757

58-
**type**: ``integer`` **default**: ``IntegerToLocalizedStringTransformer::ROUND_DOWN``
58+
**type**: ``integer`` **default**: ``\NumberFormatter::ROUND_HALFUP``
5959

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

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

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

69-
* ``IntegerToLocalizedStringTransformer::ROUND_UP`` Round away from zero.
70+
* ``\NumberFormatter::ROUND_UP`` Round away from zero. It
71+
rounds ``1.4`` to ``2`` and ``-1.4`` to ``-2``.
7072

71-
* ``IntegerToLocalizedStringTransformer::ROUND_CEILING`` Round towards
72-
positive infinity.
73+
* ``\NumberFormatter::ROUND_CEILING`` Round towards positive
74+
infinity. It rounds ``1.4`` to ``2`` and ``-1.4`` to ``-1``.
7375

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

77-
* ``IntegerToLocalizedStringTransformer::ROUND_HALF_EVEN`` Round towards the
78-
"nearest neighbor". If both neighbors are equidistant, round towards the
79-
even neighbor.
80+
* ``\NumberFormatter::ROUND_HALFEVEN`` Round towards the
81+
"nearest neighbor". If both neighbors are equidistant, round towards the even
82+
neighbor. It rounds ``2.5``, ``1.6`` and ``1.5`` to ``2`` and ``1.4`` to ``1``.
83+
84+
* ``\NumberFormatter::ROUND_HALFUP`` Round towards the
85+
"nearest neighbor". If both neighbors are equidistant, round up. It rounds
86+
``2.5`` to ``3``, ``1.6`` and ``1.5`` to ``2`` and ``1.4`` to ``1``.
87+
88+
.. deprecated:: 5.1
89+
90+
In Symfony versions prior to 5.1, these constants were also defined as aliases
91+
in the :class:`Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\IntegerToLocalizedStringTransformer`
92+
class, but they are now deprecated in favor of the :phpclass:`NumberFormatter` constants.
8093

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

8495
Overridden Options
8596
------------------

0 commit comments

Comments
 (0)