This function returns the sum of two numbers.
Arguments
Add(1,2)
Ordinal | Type | Required | Description |
1 | Number | True | First value |
2 | Number | True | Second value |
Example 1
%%[
var @sum, @num1, @num2
set @num1 = 5
set @num2 = 42
set @sum = Add(@num1, @num2)
]%%
%%=v(@num1)=%% + %%=v(@num2)=%% = %%=v(@sum)=%%
Copy
Output
5 + 42 = 47
The Add function can be used to return the sum of two numbers.
Use case: the Add function can be used for a quick way to get a sum of two numerical values. For example, if you add the sum of the last two purchases of a customer. Note that this function is limited to just two numbers in the equation but more numbers can be nested together by adding another Add function.
Syntax:
Copy Code
Add(1,2)
1 = Number of the first value in addition (number or decimal datatype)
2 = Number of the second value in addition equation (number or decimal datatype)
Example:
Copy Code
%%[
set @numbervar1 = ‘115.23’
set @numbervar2 = ‘305.46’
]%%
%%=Add(@numbervar1,@numbervar2)=%%
Output:
420.69
Explanation:
In the Add example above, the two variables are hardcoded with the numbers ‘115.23’ and ‘305.46.’ Adding both of those numbers together gets you the number of 420.69 (nice!)
The Add function can be used for whole numbers or decimals. The datatype for these values should be a number datatype or decimal or you can hardcode the numbers as it is shown in the example above.
Related functions are the Divide, Multiply, and Subtract functions.