Number Filters

Number Filters

plus filter

Adds the operand to the current value. Note that this filter behaves differently if the current value is a string

plus: Number operand

Examples

Add some numbers together

Copy
3+5 = {{3 | plus: 5}}
-4.2+2.1 = {{-4.2 | plus: 2.1}}

times filter

Multiply the input by the operand.

times: Number operand

Examples

Use the times filter to multiply a number by another number

Multiply numbers

Copy
{{4 | times:2}}
{{4.1 | times:-2.2}}

You can currently use the times to multiply a string into a list of identical strings, although this behavior is deprecated. If you need this functionality you are advised to find a different way to accomplish it.

Using the times filter with a string

Copy

Current functionality

{{"string" | times:2 | json_encode}}

Future functionality

{{"string" | times:2 | json_encode}}

Potential Replacement

{% map string for i in (1..2) %}string{% endmap -%}
{{string | json_encode}}

Alternate Replacement

{% capture string %}{% for i in (1..2) %}string{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture -%}
{{string | split:',' | json_encode}}

divided_by filter

Divide the input by operand.

divided_by: Number operand

Examples

Use the divided_by filter to divide one number by another.

Using the divided_by filter

Copy
{{8 | divided_by:2}}
{{13.3 | divided_by:1.4}}

modulo filter

Return the remainder of the input when divided by the operand.

modulo: Number operand

Examples

Use the modulo filter to get the remainder when one number is divided by another.

Using the modulo filter

Copy
{{5 | modulo:3}}
{{13.3 | modulo:1.4}}
{{-3 | modulo:2}}
{{3 | modulo:-2}}

minus filter

Subtracts the operand from the input.

minus: Number operand

Examples

Use the minus filter to subtract one number from another.

Using the minus filter

Copy
{{5 | minus:1}}
{{13.3 | minus:14.4}}

to_int filter

Converts the input to an integer.

to_int

Examples

Convert a query parameter to an integer value with a default value.

Convert to integer

Copy
{% var limit = request.query_params['limit'] | default: 20 | to_int %}

to_number filter

Converts the input to a number.

to_number

Examples

Convert a query parameter to a number with a default value.

Convert to number

Copy
{% var average = request.query_params['average'] | default: 2.5 | to_number %}