Skip to main content
All CollectionsCommunication
Math Operations in Template Smart Fields
Math Operations in Template Smart Fields

This article will go through different smart fields that can perform mathematical operations in templates.

Ron Danenberg avatar
Written by Ron Danenberg
Updated over a week ago

You can use the following smart fields in your templates to do maths operations:

  • addition – addition

  • sub – subtraction

  • mul – multiplication

  • div – division

  • intdiv – integer (floor) division

  • abs – absolute value

  • mod – modulo


Examples:

{{ 17|sub:13 }}

would return 4 (because 17 minus 13 equals to 4)

The following is a complex example combining math operations on the balance of the invoice attached:

{% with invoices.0.balance|mul:0.01|floatformat:2 as variable_interest %}

{% with invoices.0.balance|addition:10 as interest_fixed %}

The 1% variable interest is: ${{ variable_interest }}

The $10 fixed interest is: ${{ interest_fixed }}

The total interest is: ${{ variable_interest|addition:interest_fixed }}

{% endwith %}

{% endwith %}

First line: applying 1% on the balance of the invoice, and ensuring a rounding to 2 decimals in a variable variable_interest

Second line: applying $10 fixed interest rate

Fifth line: adding both variable and fixed interests


If the invoice balance is $4200, then the final result of the example above would be:

The 1% variable interest is: $42.00

The $10 fixed interest is: $4,210.00

The total interest is: $4,252.00


Did this answer your question?