This article explains what the Add(), Subtract(), Multiply() and Divide() functions are that you can use with number values and provides examples of how they can be used with the binding syntax in smart templates.
Prerequisites
|
Important
|
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 |
Using the Add() function to calculate the sum of form fields 'Number 1' and 'Number 2'. The binding is:
{{Add(Form.Number1, Form.Number2)}}
Example A | Example B | Example C | |
---|---|---|---|
Input | Form.Number1 = "8" Form.Number2 = "3" |
Form.Number1 = "8" Form.Number2 = "-3" |
Form.Number1 = "-8" Form.Number2 = "-3" |
Output | "11" | "5" | "-11" |
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'. The binding is:
{{Add(Add(Form.Number1, Form.Number2), Form.Number3)}}
Example A | Example B | Example C | |
---|---|---|---|
Input |
Form.Number1 = "8" |
Form.Number1 = "8" Form.Number2 = "-3" Form.Number3 = "4" |
Form.Number1 = "8" Form.Number2 = "0" Form.Number3 = "4" |
Output | "15" | "9" | "12" |
To calculate the sum of 4 form fields 'Number 1', 'Number 2', 'Number 3' and 'Number 4' use this binding. The binding is:
{{Add(Add(Form.Number1, Form.Number2), Add(Form.Number3, Form.Number4))}}
Example A | Example B | Example C | |
---|---|---|---|
Input |
Form.Number1 = "8" |
Form.Number1 = "8" |
Form.Number1 = "8" Form.Number2 = "0" Form.Number3 = "4" Form.Number4 = "7" |
Output | "22" | "16" | "19" |
Using the Add() function to calculate the sum of the fixed value "12" and the form field 'Number 2'. The binding is:
{{Add(12, Form.Number2)}}
Example A | Example B | Example C | |
---|---|---|---|
Input | Form.Number2 = "3" | Form.Number2 = "0" | Form.Number2 = "-3" |
Output | "15" | "12" | "9" |
Using the Add() function to calculate the sum of two data source values, with 2 decimals.
This data source is used:
NoteThe column containing the prices needs to be of Type 'Number'. |
The binding is:
$ {{Add(DataSources.Products["Apple"].Price, DataSources.Products["Banana"].Price)}}
Example | |
---|---|
Input | Apple = "0.95" Banana = "1.25" |
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'. The binding is:
{{Subtract(Form.Number1, Form.Number2)}}
Example A | Example B | Example C | |
---|---|---|---|
Input | Form.Number1 = "8" Form.Number2 = "3" |
Form.Number1 = "3" Form.Number2 = "8" |
Form.Number1 = "-3" Form.Number2 = "-8" |
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'. The binding is:
{{Multiply(Form.Number1, Form.Number2)}}
Example A | Example B | Example C | |
---|---|---|---|
Input | Form.Number1 = "8" Form.Number2 = "3" |
Form.Number1 = "8" Form.Number2 = "-1" |
Form.Number1 = "-8" Form.Number2 = "-3" |
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. The binding is:
{{Multiply(Add(Form.Number1, Form.Number2), 5)}}
Example A | Example B | Example C | |
---|---|---|---|
Input | Form.Number1 = "8" Form.Number2 = "3" |
Form.Number1 = "8" Form.Number2 = "-3" |
Form.Number1 = "-8" Form.Number2 = "-3" |
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'. The binding is:
{{Divide(Form.Number1, Form.Number2)}}
Example A | Example B | |
---|---|---|
Input | Form.Number1 = "8" Form.Number2 = "3" |
Form.Number1 = "8" Form.Number2 = "-3" |
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. The binding is:
{{FormatNumber(Divide(Form.Number1, Form.Number2), "#.##", "nl-NL")}}
Example A | Example B | |
---|---|---|
Input | Form.Number1 = "8" Form.Number2 = "3" |
Form.Number1 = "8" Form.Number2 = "-3" |
Output | "2,67" | "-2,67" |
NoteBecause the language is set to Dutch ("nl-NL"), the decimal separator does not show a period but a comma! |
Comments
Article is closed for comments.