Math filters apply mathematical operations.
Math filters can be chained and, like all filters, are applied from left to right. In this example minus is applied first, then times, then 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
abs also works on a string that contains only a number.
{{ "-19.86" | abs }}
19.86
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 | 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 | minus: 15 }}
185
plus
Adds a number to an output.
{{ product.price | plus: 15 }}
215
round
Rounds the output to the nearest integer or to the given number of decimal places.
{{ 4.6 | round }}
{{ 4.3 | round }}
{{ 4.5612 | round: 2 }}
5
4
4.56
times
Multiplies an output by a number.
{{ product.price | times: 1.15 }}
230
modulo
Divides an output by a number and returns the remainder.
{{ 12 | modulo:5 }}
2