About this article
This article will explain what the Add(), Subtract(), Multiply() and Divide() functions are that you can use with number values and provide examples of how they can be used with the binding syntax in smart templates.
 What is the Add() function?
 What is the Subtract() function?
 What is the Multiply() function?
 What is the Divide() function?
Prerequisites


What is the Add() function?
The Add() function returns the sum of two numbers.
Add() logic
Syntax  {{Add(Number, Number)}} 
Input  Two numbers 
Output  The sum of the numbers 
Example 1
Using the Add() function to calculate the sum of form fields 'Number 1' and 'Number 2'.
Binding  {{Add(Form.Number1, Form.Number2)}}  
Input 
Form.Number1 = "8" 
Form.Number1 = "8" 
Form.Number1 = "8" 
Output  "11"  "5"  "11" 
Example 2
Using the Add() function to calculate the sum of more than two numbers.
Because the Add() function only supports two numbers, you have to use nested Add() functions to calculate the sum of 3 form fields 'Number 1', 'Number 2' and 'Number 3'.
Binding  {{Add(Add(Form.Number1, Form.Number2), Form.Number3)}}  
Input 
Form.Number1 = "8" 
Form.Number1 = "8" 
Form.Number1 = "8" 
Output  "15"  "9"  "12" 
To calculate the sum of 4 form fields 'Number 1', 'Number 2', 'Number 3' and 'Number 4' use this binding.
Binding  {{Add(Add(Form.Number1, Form.Number2), Add(Form.Number3, Form.Number4))}}  
Input 
Form.Number1 = "8" 
Form.Number1 = "8" 
Form.Number1 = "8" 
Output  "22"  "16"  "19" 
Example 3
Using the Add() function to calculate the sum of the fixed value "12" and the form field 'Number 2'.
Binding  {{Add(12, Form.Number2)}}  
Input 
Form.Number2 = "3" 
Form.Number2 = "0" 
Form.Number2 = "3" 
Output  "15"  "12"  "9" 
Example 4
Using the Add() function to calculate the sum of two data source values, with 2 decimals.
This data source is used:

Binding  $ {{Add(DataSources.Products["Apple"].Price, DataSources.Products["Banana"].Price)}}  
Input 
Apple = "0.95" 

Output  "$ 2.20" 
What is the Subtract() function?
The Subtract() function returns the difference of two numbers.
Subtract() logic
Syntax  {{Subtract(Number, Number)}} 
Input  Two numbers 
Output  The difference of the numbers 
Example
Using the Subtract() function to calculate the difference of form fields 'Number 1' and 'Number 2'.
Binding  {{Subtract(Form.Number1, Form.Number2)}}  
Input 
Form.Number1 = "8" 
Form.Number1 = "3" 
Form.Number1 = "3" 
Output  "5"  "5"  "5" 
What is the Multiply() function?
The Multiply() function returns the product of two numbers.
Multiply() logic
Syntax  {{Multiply(Number, Number)}} 
Input  Two numbers 
Output  The product of the numbers 
Example 1
Using the Multiply() function to calculate the product of form fields 'Number 1' and 'Number 2'.
Binding  {{Multiply(Form.Number1, Form.Number2)}}  
Input 
Form.Number1 = "8" 
Form.Number1 = "8" 
Form.Number1 = "8" 
Output  "24"  "24"  "24" 
Example 2
Combining the Multiply() and Add() functions to calculate the sum of form fields 'Number 1' and 'Number 2' and multiply that value by 5.
Binding  {{Multiply(Add(Form.Number1, Form.Number2), 5)}}  
Input 
Form.Number1 = "8" 
Form.Number1 = "8" 
Form.Number1 = "8" 
Output  "55"  "25"  "55" 
What is the Divide() function?
The Divide() function returns the quotient of two numbers.
Divide() logic
Syntax  {{Divide(Number, Number)}} 
Input  Two numbers 
Output  The quotient of the numbers 
Example 1
Using the Divide() function to calculate the quotient of form fields 'Number 1' and 'Number 2'.
Binding  {{Divide(Form.Number1, Form.Number2)}}  
Input 
Form.Number1 = "8" 
Form.Number1 = "8" 

Output  "2.6666666666666666666666666667"  "2.6666666666666666666666666667" 
Example 2
The same as example 1 but in combination with the FormatNumber() function to set the format so the output shows a maximum of 2 decimals.
Binding  {{FormatNumber(Divide(Form.Number1, Form.Number2), "#.##", "nlNL")}}  
Input 
Form.Number1 = "8" 
Form.Number1 = "8" 

Output  "2,67"  "2,67" 

Related articles
Comments
0 comments
Article is closed for comments.