AMPscript Divide (Next)
Divide one number by another with AMPscript Divide in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including the two-decimal result and the failing zero divisor.
Syntax
Divide(dividend, divisor) → number
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
dividend |
string | number | Yes | Number to divide |
divisor |
string | number | Yes | Number to divide by |
Exactly two arguments. Numbers written as strings are accepted.
Example
%%=Divide(100, 4)=%%
Renders 25.
A quotient that does not come out even is rounded to two decimals:
%%=Divide(10, 3)=%%
Renders 3.33.
Return value
number — the quotient of the two operands.
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 Divide(10) or Divide(10, 2, 1) cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.
The result is rounded to two decimals. Divide(10, 3) renders 3.33. Even quotients have no decimals: Divide(10, 2) gives 5.
Negatives work. Divide(-10, 4) gives -2.5.
Numeric strings are accepted. Divide("100", "4") gives 25, Divide("3.5", "0.5") gives 7, and Divide(9, "2") gives 4.5.
A zero divisor breaks the render. Divide(100, 0), Divide(1, 0), Divide(7.5, 0), Divide(-100, 0), Divide(0, 0) and Divide(100, "0") all save, but the email preview then fails with HTTP 500 and no message. Check the divisor before you divide.
"true" counts as 1. Divide("true", 1) renders 1 instead of failing.
Other non-numeric input fails. Divide("abc", 1) makes the preview fail with HTTP 500.
Show Next test script
<!-- Marketing Cloud Next test script for Divide. 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=[5] got=[%%=Divide(10,2)=%%]</p>
<p>c2 expect=[3.33] got=[%%=Divide(10,3)=%%]</p>
<p>c3 expect=[-2.5] got=[%%=Divide(-10,4)=%%]</p>
<p>c4 expect=[25] got=[%%=Divide(100,4)=%%]</p>
<p>c5 expect=[25] got=[%%=Divide("100","4")=%%]</p>
<p>c6 expect=[7] got=[%%=Divide("3.5","0.5")=%%]</p>
<p>c7 expect=[4.5] got=[%%=Divide(9,"2")=%%]</p>
<p>c8 expect=[1] got=[%%=Divide("true",1)=%%]</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) -->
%%=Divide(100,0)=%%
<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Divide(1,0)=%%
<!-- email 3: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Divide(50,0)=%%
<!-- email 4: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Divide(7.5,0)=%%
<!-- email 5: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Divide(-100,0)=%%
<!-- email 6: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Divide(0,0)=%%
<!-- email 7: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Divide(100,"0")=%%
<!-- email 8: expect that the save is rejected (HTTP 400) -->
%%=Divide(10)=%%
<!-- email 9: expect that the save is rejected (HTTP 400) -->
%%=Divide(10,2,1)=%%
<!-- email 10: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Divide("abc",1)=%%
Differs from official docs
- Two-decimal rounding. The official reference says nothing about rounding the quotient. In Next,
Divide(10, 3)renders3.33. Details - Zero divisor. The official reference does not cover a divisor of zero. In Next, every zero divisor tried made 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 renders Divide(10,3) as 3.33333333333333 (Next: 3.33) and a zero divisor as ∞, -∞ or NaN, where Next breaks the email preview. Engagement aborts on Divide("true",1), while Next renders 1. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
Mod— the remainder of the same divisionMultiply— the inverse operation- Official reference