Mod Function

The Mod function can be used to return the remainder after a division equation. Note that “Mod” is short for “modulo.”

Use case: the Mod function can be used with a modulo operation which is the operation that produces such a remainder when given a dividend and divisor. In other words, when you divide two numbers that produce a remainder.

Note that this function is limited to just two numbers in the equation but you can next the function if you need to add more numbers.

Syntax:



Mod(1,2)
1 = Number of the first value as the dividend (number or decimal datatype)
2 = Number of the second value as the divisor (number or decimal datatype)

Example:



%%[
set @numberValue1 = “69”
set @numberValue2 = “8”
]%%
%%=Mod(@numberValue1, @numberValue2)=%%




Output:

5

Explanation:

In the Mod example above, the two variables are hardcoded with the numbers ’69’ (nice) and ‘8.’ The remainder value is ‘5’. If you work that backwards, you’ll see that 8 multiplied by 8 is 64 and 64 + 5 = 69. Or in other words, 69/8 = 8 with a remainder of 5.

The Mod 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, Add, Multiply, and Subtract functions

Leave a Reply

Your email address will not be published. Required fields are marked *