Skip to content

Math Transforms

Normative reference

See the Transforms reference for the normative definition of each transform below, plus worked examples.

All 11 transforms below read a numeric input (and, where applicable, a numeric argument), compute in floating point, and emit a number — collapsing whole-number results so 6.0 renders as 6 (see Number Rendering). A non-numeric input is a soft failure (TypeMismatch) yielding null; a non-numeric argument is a transform error.

Name Arguments Description
abs Absolute value.
ceil Rounds up to the nearest integer.
floor Rounds down to the nearest integer.
round places? (non-negative integer, default 0) Rounds to places decimal places, halves rounding away from zero (matching Shopify Liquid / Ruby). A negative places is a degenerate-value soft failure.
plus: operand Adds operand.
minus: operand Subtracts operand.
times: operand Multiplies by operand.
divided_by: operand True (non-truncating) division — 7 \| divided_by: 2 is 3.5, unlike Shopify Liquid's truncating division. A zero divisor is a soft failure yielding null.
modulo: operand Remainder. A zero divisor is a soft failure yielding null.
at_least: minimum Returns the larger of the input and minimum.
at_most: maximum Returns the smaller of the input and maximum.

Date-time-aware arithmetic

plus, minus, at_least, and at_most also accept a date-time input (see Date/Time Transforms):

  • dateTime | plus: n — shifts the date-time forward n days.
  • dateTime | minus: n — shifts the date-time back n days, when n is numeric.
  • dateTime | minus: otherDateTime — returns the signed number of days between the two instants as a number.
  • dateTime | at_least: otherDateTime / at_most: otherDateTime — returns whichever date-time is later/earlier. The argument must itself be a date-time in this form; a numeric argument here is a type-mismatch soft failure.

Examples

{{ -4.5 | abs }}              {{! 4.5 }}
{{ 4.2 | ceil }}               {{! 5 }}
{{ 4.8 | floor }}               {{! 4 }}
{{ 3.14159 | round: 2 }}        {{! 3.14 }}
{{ 7 | divided_by: 2 }}          {{! 3.5 }}
{{ 7 | modulo: 2 }}               {{! 1 }}
{{ 3 | at_least: 5 }}              {{! 5 }}
{{ 3 | at_most: 5 }}                {{! 3 }}

Where to next