blob: 2c970b7f9e19ebdb70906ef59fe5db7268a219fe [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001``round``
2=========
3
4The ``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
14The ``round`` filter takes two optional arguments; the first one specifies the
15precision (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
30Arguments
31---------
32
33* ``precision``: The rounding precision
34* ``method``: The rounding method