plus
Adds a number to another number.
minus
Subtracts a number from another number.
times
Multiplies a number by another number.
divided_by
Divides a number by another number. The result is the string obtained by JavaScript .toString()
of the result number.
number
and we cannot tell the difference. For example:
integerArithmetic
argument to enforce integer divide:
modulo
Returns the remainder of a division operation.
abs
Liquid filter that returns the absolute value of a number.
abs
will also work on a string that only contains a number:
at_least
Limits a number to a minimum value.
at_most
Limits a number to a maximum value.
ceil
Rounds the input up to the nearest whole number. LiquidJS tries to convert the input to a number before the filter is applied.
floor
Rounds the input down to the nearest whole number. LiquidJS tries to convert the input to a number before the filter is applied.
round
Rounds a number to the nearest integer or, if a number is passed as an argument, to that number of decimal places.
sum
Computes the sum of all the numbers in an array.
An optional argument specifies which property of the array’s items to sum up.
In this example, assume the object cart.products
contains an array of all products in the cart of a website.
Assume each cart product has a qty
property that gives the count of that product instance in the cart.
Using the sum
filter we can calculate the total number of products in the cart.