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}}
calc
{{calc "price * quantity"}}
{{calc "price * 5"}}
Numerical Calculation in Loops & Tables
You can also use Numerical Calculation in Loops & Tables.
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:
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.
{{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.
{{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.
{{round number}}
198.58
199
{{round input}}
-187.74
-188
Using calc Helper for Simplified Calculations
The calc
helper is designed to simplify calculations within templates, enabling direct numerical operations—such as addition, subtraction, multiplication, and division— and supports complex operations with a single syntax. This functionality allows for dynamic number processing, enhancing the efficiency of document automation.
Syntax
You can use the `calc` helper with the following syntax:
{{calc "expression"}}
Operator
Syntax
Input
Output
Add
{{calc "price + tax"}}
price = 500 tax = 30
530
Subtract
{{calc "price - discount"}}
price = 100 discount = 10
90
Multiply
{{calc "price * quantity"}}
price = 50 quantity = 10
500
Divide
{{calc "price / quantity"}}
price = 100 quantity = 4
25
Multiple operators
{{calc "price - (price * discount /100)"}}
price = 500 discount = 10
450
Using calc
Helper for Advanced Calculations
calc
Helper for Advanced CalculationsThe calc
helper works seamlessly within dynamic placeholders and nested calculations, addressing more complex use-cases. Below are few examples of how you can use it.
Using `calc` in Conditional Logic
You can also perform calculations within conditions to make decisions based on calculated values.
Input
Output
price = 100 quantity = 30
Discount Applied
price = 100 quantity = 3
No Discount
Using `calc` in Loops
You can use calc
inside loops to dynamically compute values for repeating elements in templates.
Using calc
in manipulating numerical values
calc
in manipulating numerical valuesDescription
Syntax
Input
Output
Convert to Words
{{number_to_words (calc "price * quantity")}}
price = 10 quantity = 5
fifty
Rounding (`round()`)
{{round (calc "price / quantity")}}
price = 50 quantity = 3
17
Ceiling (`ceil()`)
{{ceil (calc "price / quantity")}}
price = 50 quantity = 3
17
Floor (`floor()`)
{{floor (calc "price / quantity")}}
price = 50 quantity = 3
16
Last updated
Was this helpful?