Math Filters
These filters provide mathematical operations for use in Liquid templates. They allow you to perform calculations, rounding, and comparisons directly in your templates. Use these filters to manipulate numeric values, enforce limits, and perform arithmetic as needed.
abs
Returns the absolute value of a number.
Input
{{ -17 | abs }}Output
17at_least
Limits a number to a minimum value.
Input
{{ 1 | at_least: 2 }}Output
2at_most
Limits a number to a maximum value.
Input
{{ 1 | at_most: 2 }}Output
1ceil
Rounds an input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
Input
{{ 1.2 | ceil }}
{{ 2.0 | ceil }}
{{ "183.357" | ceil }}Output
2
2
184divided_by
Divides a number by another number. The result is rounded down to the nearest integer (that is, the floor) if the divisor is an integer.
Input
{{ 16 | divided_by: 4 }}
{{ 5 | divided_by: 3 }}Output
4
1floor
Rounds an input down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
Input
{{ 1.2 | floor }}
{{ 2.0 | floor }}
{{ "183.357" | floor }}Output
1
2
183max
Outputs the maximum value.
Input
{{ 1 | max: 2 }}Output
2min
Outputs the minimum value.
Input
{{ 1 | min: 2 }}Output
1minus
Subtracts a number from another number.
Input
{{ 4 | minus: 2 }}Output
2modulo
Returns the remainder of a division operation.
Input
{{ 3 | modulo: 2 }}Output
1plus
Adds a number to another number.
Input
{{ 4 | plus: 2 }}Output
6power
Calculates a power.
Input
{{ 2 | max: 2 }}Output
4round
Rounds a number to the nearest integer or, if a number is passed as an argument, to that number of decimal places.
Input
{{ 1.2 | round }}Output
1times
Multiplies a number by another number.
Input
{{ 3 | times: 2 }}Output
6