round
The round
filter rounds a number to a specified precision.
For example:
{{ 10.5678|round }}
will print 11
{{ 10.5678|round(1) }}
will print 10.6
{{ 10.5678|round(2) }}
will print 10.57
{{ 10.5678|round(3) }}
will print 10.568
The round filter takes two optional arguments; the first one specifies the precision (default is 0) and the second the rounding method (default is common):
- common rounds either up or down (rounds the value up when it is halfway or more to the next whole number, rounds the value down when it is less than half way)
- ceil always rounds up
- floor always rounds down
{{ 10.56|round }}
will print 11
{{ 10.44|round }}
will print 10
{{ 10.44|round(1, 'ceil') }}
will print 10.5
{{ 10.789|round(1, 'floor') }}
will print 10.7