Math filters

Math filters allow you to apply mathematical tasks.

Math filters can be linked and, as with any other filters, are applied in order of left to right. In the example below, minus is applied first, then times, and finally divided_by.

You save {{ product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price }}%

abs

Returns the absolute value of a number.

{{ -17 | abs }}
17

at_most

Limits a number to a maximum value.

{{ 4 | at_most: 5 }}
{{ 4 | at_most: 3 }}
4
3

at_least

Limits a number to a minimum value.

{{ 4 | at_least: 5 }}
{{ 4 | at_least: 3 }}
5
4

ceil

Rounds an output up to the nearest integer.

{{ 4.6 | ceil }}
{{ 4.3 | ceil }}
5
5

divided_by

Divides an output by a number. The output is rounded down to the nearest integer.

<!-- product.price = 200 -->
{{ product.price | divided_by: 10 }}
20

floor

Rounds an output down to the nearest integer.

{{ 4.6 | floor }}
{{ 4.3 | floor }}
4
4

minus

Subtracts a number from an output.

<!-- product.price = 200 -->
{{ product.price | minus: 15 }}
185

plus

Adds a number to an output.

<!-- product.price = 200 -->
{{ product.price | plus: 15 }}
215

round

Rounds the output to the nearest integer or specified number of decimals.

{{ 4.6 | round }}
{{ 4.3 | round }}
{{ 4.5612 | round: 2 }}
5
4
4.56

times

Multiplies an output by a number.

<!-- product.price = 200 -->
{{ product.price | times: 1.15 }}
230

modulo

Divides an output by a number and returns the remainder.

{{ 12 | modulo:5 }}
2

Did this page help you?