# Math Filters

Math filter work on numbers (either integer or float) and will transform the (numerical) input to a (numerical) output. Please remark that the output of the decimal point of floats depends on the localization (most often either a dot or a comma is used as decimal point).

Quite often float results are quite imprecise, e.g. 4 - 1.2 is 2,79999995231628. Even though the value is quite correct (as 2,7999999… is actually 2.8), if you want to output the value somewhere on the web page, you should round the value to a given number of decimal places using the round filter. E.g. {{ 4 | minus: 1.2 | round: 1 }} will output 2.8.

## ceil

The ceil filter will return the next integer number (of type float) which is larger or equal than the input.

Example:

``````
{{ 3.2 | ceil }}
{{ 4.0 | ceil }}
``````

Output:

``````
4
4
``````

## divided_by

This filter divides the input by the additional parameter. The operation of this filter depends on whether the input values are ints or at least one of them is a float. If both operands are int, the result will also be an int (thus 5/2 will result in 2, as it will be rounded down to the next integer). Otherwise the result is a float with decimal places.

Example:

``````
{{ 5 | divided_by: 2 }}
{{ 5.0 | divided_by: 2.0 }}
{{ 5 | divided_by: 2.0 }}
``````

Output:

``````
2
2,5
2,5
``````

## floor

The floor filter will return the next integer number (of type float) which is smaller or equal than the input.

Example:

``````
{{ 4.8 | floor }}
{{ 4.0 | floor }}
``````

Output:

4 4

## minus

Substracts the parameter from the input. A float result may be subject to calculation imprecision (as can be seen in the example).

Example:

``````
{{ 4 | minus: 1 }}
{{ 4 | minus: 1.2 }}
``````

Output:

``````
3
2,79999995231628
``````

## modulo

Modulo calculates the remainder of the division of the input with the parameter. Most often this operation is used with ints, but this operation also works with floats.

Example:

``````
{{ 5 | modulo: 3 }}
{{ 5.1 | modulo: 2.3 }}
{{ -5 | modulo: 3 }}
``````

Output:

``````
2
0,5
-2
``````

## plus

Adds the input and the parameter.

Example:

``````
{{ 5 | plus: 3 }}
{{ 5.1 | plus: 2.3 }}
``````

Output:

``````
8
7,4
``````

## round

This filter rounds the input either to the nearest integer, or when a parameter is specified to the given number of decimal points.

Example:

``````
{{ 4.6 | round }}
{{ 4.6352 | round: 2 }}
``````

Output:

``````
5
4,64
``````

## times

The times filter can be used with numbers and strings as input, but the filter have different meanings for the two cases. While it reproduces the given string as many times as specified as parameter, it will on the other hand multiply an input number with the parameter number.

Example:

``````
{{ 4 | times: 3 }}
{{ 4.25 | times: 5 }}
``````

Output:

``````
12
21,25
``````