Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``round`` |
| 2 | ========= |
| 3 | |
| 4 | The ``round`` filter rounds a number to a given precision: |
| 5 | |
| 6 | .. code-block:: twig |
| 7 | |
| 8 | {{ 42.55|round }} |
| 9 | {# outputs 43 #} |
| 10 | |
| 11 | {{ 42.55|round(1, 'floor') }} |
| 12 | {# outputs 42.5 #} |
| 13 | |
| 14 | The ``round`` filter takes two optional arguments; the first one specifies the |
| 15 | precision (default is ``0``) and the second the rounding method (default is |
| 16 | ``common``): |
| 17 | |
| 18 | * ``common`` rounds either up or down (rounds the value up to precision decimal |
| 19 | places away from zero, when it is half way there -- making 1.5 into 2 and |
| 20 | -1.5 into -2); |
| 21 | |
| 22 | * ``ceil`` always rounds up; |
| 23 | |
| 24 | * ``floor`` always rounds down. |
| 25 | |
| 26 | .. note:: |
| 27 | |
| 28 | The ``//`` operator is equivalent to ``|round(0, 'floor')``. |
| 29 | |
| 30 | Arguments |
| 31 | --------- |
| 32 | |
| 33 | * ``precision``: The rounding precision |
| 34 | * ``method``: The rounding method |