Docupilot
HomeLoginSignup
  • Docupilot Help Documentation
  • Getting Started
  • Building Templates
    • Tokens (Merge Field)
    • Document Builder
    • AI-Powered Template Builder
    • Word Document (DOCX) & PowerPoint (PPTX)
    • Excel (XLSX)
    • Fillable PDF
    • Template Preferences
    • Formatting Your Data
    • Numerical Calculations
    • Advanced usage
  • Test your document template
  • Deliveries
    • Email
    • Webhook
    • Dropbox
    • Google Drive
    • One Drive
    • DropboxSign (formerly Hellosign)
    • DocuSign
    • SignNow
    • Xodo sign (formerly Eversign)
    • Signable
    • Yousign
    • Amazon S3
    • Azure Blob Delivery
    • SFTP
    • Box Drive
  • Create document
    • Data Capture Form
    • API & Webhook Integration
    • Bulk Create
    • Integrate with Zapier
    • Integrate with Make
    • Integrate with Zoho Flow
    • Integrate with Integrately
  • Integrations
    • Google Forms
    • Google Sheets
    • Airtable Extension
    • Microsoft Word Add-In
  • Collaborating with multiple users
    • Invite users
    • Manage & delete users
  • Reports
  • Settings
    • Workspace
    • API Settings
    • Manage Subscription
    • Linked Accounts
  • Folders & Templates management
    • Manage Folders
    • Manage Templates
    • Share Templates & Folders
  • Profile & Account Security
  • Frequently Asked Questions (FAQs)
  • Developers
    • API Overview
    • Templates API
    • Folders API
  • Updates
    • Scheduled Downtime Notification
Powered by GitBook
On this page
  • Numerical Calculation in Loops & Tables
  • Incrementing @index in Loops & Tables
  • Rounding of numbers
  • Using calc Helper for Simplified Calculations
  • Using calc Helper for Advanced Calculations

Was this helpful?

  1. Building Templates

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.

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 syntax
Input
Output

{{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 syntax
Input
Output

{{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 syntax
Input
Output

{{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

Note: Calculations follow standard mathematical precedence (BODMAS rules).

Using calc Helper for Advanced Calculations

The 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.

{{#if ((calc "price * quantity") > 1000)}}
Discount Applied 
{{else}} 
No Discount 
{{/if}}

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

Description

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

PreviousFormatting Your DataNextAdvanced usage

Last updated 2 months ago

Was this helpful?