Divide
Divides the first number by the second. Runtime-proven on a live Marketing Cloud Engagement CloudPage — including the undocumented zero-divisor result, which renders an infinity symbol instead of failing.
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 |
Example
%%[
VAR @unitPrice
SET @unitPrice = Divide(29.97, 3)
]%%
Per unit: %%=v(@unitPrice)=%%
Renders Per unit: 9.99.
A zero divisor renders ∞ rather than failing, so guard the divisor before you use the result:
%%[
VAR @count, @average
SET @count = AttributeValue("ItemCount")
IF @count > 0 THEN
SET @average = Divide(AttributeValue("OrderTotal"), @count)
ENDIF
]%%
Return value
number — the quotient of the two operands.
A zero divisor does not raise an error: a non-zero dividend yields the infinity symbol and a zero dividend yields NaN. Guard against a zero divisor before rendering the result. Both of those are IEEE numeric values rather than a closed set of status tokens, so there is nothing to pattern-match beyond the two literals.
Behaviour
Non-integer quotients render as decimals. Divide(10, 3) renders 3.33333333333333 — the value is not rounded to an integer.
Negatives work as expected. Divide(-10, 4) gives -2.5.
Numeric strings are accepted. Divide("100", "4") gives 25, Divide("3.5", "0.5") gives 7, and mixing forms as in Divide(9, "2") gives 4.5.
Non-numeric input aborts the page. A non-numeric string (Divide("abc", 1)) and a boolean-like string (Divide("true", 1)) each abort the CloudPage with HTTP 422, discarding all output rendered before the call.
Dividing by zero
This is the load-bearing finding for this function, and it is not mentioned by the official reference at all.
A zero divisor does not raise an error and does not abort the page. Instead:
| Call | Renders |
|---|---|
Divide(100, 0) |
∞ |
Divide(1, 0) |
∞ |
Divide(7.5, 0) |
∞ |
Divide(-100, 0) |
-∞ |
Divide(0, 0) |
NaN |
Divide(100, "0") |
∞ |
The glyph is genuinely U+221E, confirmed by dumping the codepoints of the rendered line. A zero divisor passed as a numeric string behaves identically to the numeric zero.
The practical consequence is that an unguarded division by zero does not fail loudly — the ∞ flows straight into the rendered message and ships to the recipient. Check the divisor yourself before dividing.
A console that is not reading the response as UTF-8 displays ∞ as the digit 8. During verification that misread the result entirely until the response was re-fetched as UTF-8 and the codepoints dumped. Always codepoint-check a suspicious literal before drawing a conclusion.
Both zero-divisor behaviours are catalogued as findings on Differs from official docs, alongside the contrasting behaviour of Mod, which renders NaN in every zero-divisor case.
Show test script
%%[
VAR @b
SET @b = RequestParameter("b")
/* safe sweep: everything here is accepted and can share one request */
IF @b == "safe" THEN
OutputLine(Concat("Divide(100,4)=[", Divide(100,4), "]"))
OutputLine(Concat("Divide('100','4')=[", Divide("100","4"), "]"))
OutputLine(Concat("Divide('3.5','0.5')=[", Divide("3.5","0.5"), "]"))
OutputLine(Concat("Divide(9,'2')=[", Divide(9,"2"), "]"))
OutputLine(Concat("Divide(10,3)=[", Divide(10,3), "]"))
OutputLine(Concat("Divide(-10,4)=[", Divide(-10,4), "]"))
ENDIF
/* zero divisor: does NOT abort, so all cases can share one request */
IF @b == "d0" THEN
OutputLine(Concat("Divide(100,0)=[", Divide(100,0), "]"))
OutputLine(Concat("Divide(1,0)=[", Divide(1,0), "]"))
OutputLine(Concat("Divide(7.5,0)=[", Divide(7.5,0), "]"))
OutputLine(Concat("Divide(-100,0)=[", Divide(-100,0), "]"))
OutputLine(Concat("Divide(0,0)=[", Divide(0,0), "]"))
OutputLine(Concat("Divide(100,'0')=[", Divide(100,"0"), "]"))
ENDIF
/* each risky branch aborts the page: the start marker never renders */
IF @b == "few" THEN
OutputLine(Concat("few start"))
OutputLine(Concat("Divide(1)=[", Divide(1), "]"))
ENDIF
IF @b == "many" THEN
OutputLine(Concat("many start"))
OutputLine(Concat("Divide(1,2,3)=[", Divide(1,2,3), "]"))
ENDIF
IF @b == "str" THEN
OutputLine(Concat("str start"))
OutputLine(Concat("Divide('abc',1)=[", Divide("abc",1), "]"))
ENDIF
IF @b == "bool" THEN
OutputLine(Concat("bool start"))
OutputLine(Concat("Divide('true',1)=[", Divide("true",1), "]"))
ENDIF
]%%
OutputLine given a bare string literal renders an empty line. Wrap the argument in Concat() or your start and done markers vanish silently — which looks exactly like the function failing.
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
See also
Mod— the sibling remainder function, which handles a zero divisor differentlyMultiply— the inverse operation- Differs from official docs — the zero-divisor finding
- Official reference · ampscript.guide