AMPscript Mod (Next)
Get the remainder of a division with AMPscript Mod in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including the sign rule and the inputs that break the preview.
Syntax
Mod(dividend, divisor) → number
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
dividend |
number | Yes | Number to divide |
divisor |
number | Yes | Number to divide by |
Exactly two arguments. Pass numeric literals or numeric variables: a number written as a string breaks the render in Next.
Example
%%=Mod(10, 3)=%%
Renders 1.
%%=Mod(500, 12)=%%
Renders 8.
Return value
number — the remainder left after dividing the first number by the second.
There is no special value for a zero divisor in Next: the render fails instead (see below).
Behaviour
Exactly two arguments. An email that calls Mod(10) or Mod(10, 3, 1) cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.
The sign follows the dividend.
| Call | Renders |
|---|---|
Mod(10, 3) |
1 |
Mod(-10, 3) |
-1 |
Mod(10, -3) |
1 |
Mod(-10, -3) |
-1 |
Decimal operands work, with their own number format. Mod(10.5, 3) gives 1.5, Mod(10, 3.5) gives 3.0 (with a trailing .0), and Mod(-500.123, 12.456) gives -1.883.
A dividend smaller than the divisor broke the render. Mod(3, 10) saved, but the email preview failed with HTTP 500 instead of giving 3.
A zero divisor breaks the render. Mod(10, 0), Mod(-10, 0) and Mod(0, 0) all make the preview fail with HTTP 500. Check the divisor first.
Numeric strings break the render. Mod("10", "3"), Mod(10, "3") and Mod("10.5", "0.25") save, but the preview then fails.
Non-numeric input fails. Mod("abc", 3), Mod("true", 3) and Mod(Now(), 3) each make the preview fail with HTTP 500.
Show Next test script
<!-- Marketing Cloud Next test script for Mod. Paste it into the HTML component of a
Next email and open the preview. Each line prints the result Next gave when the call
was rendered on its own (expect) next to the result of this run (got).
Assembled from single-call test emails (dates on the page); it has not been
run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[1] got=[%%=Mod(10,3)=%%]</p>
<p>c2 expect=[-1] got=[%%=Mod(-10,3)=%%]</p>
<p>c3 expect=[1.5] got=[%%=Mod(10.5,3)=%%]</p>
<p>c4 expect=[8] got=[%%=Mod(500,12)=%%]</p>
<p>c5 expect=[1] got=[%%=Mod(10,-3)=%%]</p>
<p>c6 expect=[-1] got=[%%=Mod(-10,-3)=%%]</p>
<p>c7 expect=[-1.883] got=[%%=Mod(-500.123,12.456)=%%]</p>
<p>c8 expect=[3.0] got=[%%=Mod(10,3.5)=%%]</p>
Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
would stop the whole preview or block the save. -->
<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod(10,0)=%%
<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod(3,10)=%%
<!-- email 3: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod("10","3")=%%
<!-- email 4: expect that the email saves, but the preview never shows the new version (no fresh render) -->
%%=Mod(10,"3")=%%
<!-- email 5: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod("10.5","0.25")=%%
<!-- email 6: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod(0,0)=%%
<!-- email 7: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod(-10,0)=%%
<!-- email 8: expect that the save is rejected (HTTP 400) -->
%%=Mod(10)=%%
<!-- email 9: expect that the save is rejected (HTTP 400) -->
%%=Mod(10,3,1)=%%
<!-- email 10: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod("abc",3)=%%
<!-- email 11: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod("true",3)=%%
<!-- email 12: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Mod(Now(),3)=%%
Differs from official docs
- Decimal result format. The official decimal example states a result with a floating-point tail. In Next the same call,
Mod(-500.123, 12.456), renders-1.883, andMod(10, 3.5)renders3.0. Details - Dividend smaller than divisor. The official reference accepts any two numbers. In Next,
Mod(3, 10)saved, but the email preview failed with HTTP 500 (one probe). Details - Zero divisor. The official reference does not cover a divisor of zero. In Next,
Mod(10, 0),Mod(-10, 0)andMod(0, 0)make the email preview fail with HTTP 500. Details
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
Engagement accepts numeric strings (Mod("10","3") gives 1), renders Mod(3,10) as 3 and a zero divisor as NaN; in Next all of these break the email preview. Decimal results are written differently: Mod(10,3.5) gives 3 in Engagement and 3.0 in Next, Mod(-500.123,12.456) gives -1.88300000000001 in Engagement and -1.883 in Next. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
Divide— the quotient of the same divisionRandom— pairs withModfor bucketing- Official reference