Number filters

Arithmetic and rounding filters. All are standard Shopify Liquid except to_integer. Numeric inputs preserve integer type when both operands are integers, otherwise the result is a float.

Arithmetic

plus

Adds the argument.

{{ 10 | plus: 5 }}   <!-- 15 -->

minus

Subtracts the argument.

{{ 10 | minus: 3 }}   <!-- 7 -->

times

Multiplies by the argument.

{{ 6 | times: 7 }}   <!-- 42 -->

divided_by

Divides by the argument. When both operands are integers this is integer (floor) division; a float operand produces a float. Division by zero returns the input unchanged.

{{ 7 | divided_by: 2 }}       <!-- 3   (integer division) -->
{{ 7 | divided_by: 2.0 }}     <!-- 3.5 -->

modulo

The remainder of division. Modulo by zero returns the input unchanged.

{{ 13 | modulo: 5 }}   <!-- 3 -->

Rounding

abs

Absolute value.

{{ -8 | abs }}   <!-- 8 -->

ceil

Rounds up to the nearest integer.

{{ 3.2 | ceil }}   <!-- 4 -->

floor

Rounds down to the nearest integer.

{{ 3.8 | floor }}   <!-- 3 -->

round

Rounds to the given number of decimal places (default 0). With 0 places the result is an integer.

{{ 3.14159 | round }}      <!-- 3 -->
{{ 3.14159 | round: 2 }}   <!-- 3.14 -->

Bounds

at_least

Clamps the value up to a minimum — max(input, arg).

{{ 3 | at_least: 5 }}   <!-- 5 -->
{{ 8 | at_least: 5 }}   <!-- 8 -->

at_most

Clamps the value down to a maximum — min(input, arg).

{{ 8 | at_most: 5 }}   <!-- 5 -->
{{ 3 | at_most: 5 }}   <!-- 3 -->

Coercion

to_integer

(extension) Coerces any value to a real integer, usable in arithmetic. Float values truncate toward zero, numeric strings parse, true/false become 1/0, and nil or non-numeric values become 0. Values beyond the 64-bit range saturate rather than erroring; NaN becomes 0.

{{ "3.9" | to_integer }}         <!-- 3 -->
{{ "42" | to_integer | plus: 8 }}  <!-- 50 -->

See also