Questions & Feedback
Found a typo or an error?
Want to improve this document?Edit it.
Need support or have a technical question?
Ask support onStack Overflow.
License
Twigdocumentation is licensed under the new BSDlicense.
round
Theround
filter rounds a number to a given precision:
12345
{{ 42.55|round }}{# outputs 43 #}{{ 42.55|round(1, 'floor') }}{# outputs 42.5 #}
Theround
filter takes two optional arguments; the first one specifies theprecision (default is0
) and the second the rounding method (default iscommon
):
common
rounds either up or down (rounds the value up to precision decimalplaces away from zero, when it is half way there -- making 1.5 into 2 and-1.5 into -2);ceil
always rounds up;floor
always rounds down.
Note
The//
operator is equivalent to|round(0, 'floor')
.
Arguments
precision
: The rounding precisionmethod
: The rounding method