Numerical Calculations

Want to calculate the numerical value for a field based on merge tokens? You can do so by entering your mathematical equation in the format below.

Operation

Syntax with two variables

Syntax with a variable & constant

Addition

{{add x y}}

{{add x 10}}

Subtraction

{{subtract x y}}

{{subtract x 10}}

Multiply

{{multiply x y}}

{{multiply x 10}}

Divide

{{divide x y}}

{{divide x 10}}

Modulo

{{modulo x y}}

{{modulo x 10}}

Rounding of numbers

{{ceil x}} / {{floor x}} / {{round x}}

Numerical Calculation in Loops & Tables

You can also use Numerical Calculation in Loops & Tables.

Example
{{#each line_items}}

Name: {{Name}}
Qty: {{Qty}}
Price: {{Price}}
Total: {{multiply Qty Price}}

{{/each}}

Incrementing @index in Loops & Tables

When iterating through a list, @index is useful for displaying the position of each element within the loop. By default, @index starts from 0. However, you can adjust it to start from 1 by using the addition operator.

Syntax for Incrementing @index

To increment @index so that numbering starts from 1, you can use the add operator like this: {{add @index 1}}.

Example

Here's how you can use @index in a loop to display a sequence number along with other item details in a table format:

Example
{{#each line_items}}
Sno: {{add @index 1}}
Name: {{Name}}
Qty: {{Qty}}
Price: {{Price}}
Total: {{multiply Qty Price}}
{{/each}}

Rounding of numbers

Rounding of the numbers can be done using the helpers ceil, floor, and round.

Ceil

The helper ceil will round off the number to the nearest positive number which is greater than or equal to the give input number.

Example syntaxInputOutput

{{ceil number}}

198.58

199

{{ceil input}}

187.24

188

Floor

The helper floor will round off the number to the nearest positive number which is lesser than or equal to the given input number.

Example syntaxInputOutput

{{floor number}}

198.58

198

{{floor input}}

187.24

187

Round

Round helper will round of the given number in accordance with the value in it's decimal place. If the value in decimal places is greater than 50, then it will round of to the succeding number.

Example syntaxInputOutput

{{round number}}

198.58

199

{{round input}}

-187.74

-188

Last updated