AMPscript FormatNumber (Next)
Format a number with a standard pattern, optionally for a locale, with AMPscript FormatNumber in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including rounding and ignored custom patterns.
Syntax
FormatNumber(number, format[, locale]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
number |
string | number | Yes | Value to format; a numeric string works and may carry thousands separators |
format |
string | Yes | Standard pattern letter with an optional precision digit, or a custom pattern |
locale |
string | No | Locale supplying separators and the currency symbol; hyphen or underscore |
In Next a custom pattern is accepted at save but returns the number unformatted. Use a standard pattern letter.
Example
%%=FormatNumber(1234.555, "N2", "de-DE")=%%
Renders 1.234,56; with en-US it renders 1,234.56.
A precision digit sets the decimals:
%%=FormatNumber(1234.555, "N0")=%%
Renders 1,235.
Return value
string — the formatted number.
The result is open text. An unknown or custom pattern returns the number as it was passed in.
Behaviour
Standard patterns on 1234.555:
| Pattern | Result |
|---|---|
C |
$1,234.56 |
E |
1.234555E03 |
F |
1234.56 |
G |
1234.555 |
N |
1,234.56 |
P |
123,455.500% |
R |
1234.555 |
N0 |
1,235 |
N3 |
1,234.555 |
C0 |
$1,235 |
Lowercase c and n give the same output as their capitals. On the integer 123, D gives 123 and X gives 7B.
Custom and unknown patterns return the number unchanged. 0000, ###0 and #0.00 on -1234.555 all give -1234.555; #,##0.00 and qqqq on 1234.555 give 1234.555; the two-section #0.00;(#0.00) on -1234.555 also gives -1234.555.
Halves round to the even digit.
| Input | Pattern | Result |
|---|---|---|
2.5 |
N0 |
2 |
3.5 |
N0 |
4 |
-2.5 |
N0 |
-2 |
1.005 |
N2 |
1.00 |
1.004 |
N2 |
1.00 |
Negatives get a minus sign. -1234.555 gives -1,234.56 with N2 and -$1,234.56 with C2.
A numeric string works like the number. "1234.555" with N2 gives 1,234.56, and "1234.5" gives 1,234.50.
Locales. With N2 on 1234.555:
| Locale | Result |
|---|---|
en-US |
1,234.56 |
en_US |
1,234.56 |
de-DE |
1.234,56 |
de |
1.234,56 |
fr-FR |
1 234,56 (group separator U+202F) |
ja-JP |
1,234.56 |
hi-IN |
1,234.56 |
zz-ZZ |
1,234.56 |
"" |
1,234.56 |
With a currency pattern the locale also sets the symbol: C2 with de-DE gives 1.234,56 € (U+00A0 before the euro sign), and C with ja-JP gives ¥1,235 with the full-width yen sign U+FFE5.
Two arguments are the minimum. An email with FormatNumber(@value) cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.
Show Next test script
<!-- Marketing Cloud Next test script for FormatNumber. 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,234.50] got=[%%=FormatNumber("1234.5","N2")=%%]</p>
<p>c2 expect=[1,235] got=[%%=FormatNumber(1234.555,"N0")=%%]</p>
<p>c3 expect=[1.234,56] got=[%%=FormatNumber(1234.555,"N2","de-DE")=%%]</p>
<p>c4 expect=[2] got=[%%=FormatNumber(2.5,"N0")=%%]</p>
<p>c5 expect=[$1,234.56] got=[%%=FormatNumber(1234.555,"C")=%%]</p>
<p>c6 expect=[1.234555E03] got=[%%=FormatNumber(1234.555,"E")=%%]</p>
<p>c7 expect=[1234.56] got=[%%=FormatNumber(1234.555,"F")=%%]</p>
<p>c8 expect=[1234.555] got=[%%=FormatNumber(1234.555,"G")=%%]</p>
<p>c9 expect=[1,234.56] got=[%%=FormatNumber(1234.555,"N")=%%]</p>
<p>c10 expect=[123,455.500%] got=[%%=FormatNumber(1234.555,"P")=%%]</p>
<p>c11 expect=[1234.555] got=[%%=FormatNumber(1234.555,"R")=%%]</p>
<p>c12 expect=[1,234.555] got=[%%=FormatNumber(1234.555,"N3")=%%]</p>
<p>c13 expect=[$1,235] got=[%%=FormatNumber(1234.555,"C0")=%%]</p>
<p>c14 expect=[$1,234.56] got=[%%=FormatNumber(1234.555,"c")=%%]</p>
<p>c15 expect=[1,234.56] got=[%%=FormatNumber(1234.555,"n")=%%]</p>
<p>c16 expect=[123] got=[%%=FormatNumber(123,"D")=%%]</p>
<p>c17 expect=[7B] got=[%%=FormatNumber(123,"X")=%%]</p>
<p>c18 expect=[1234.555] got=[%%=FormatNumber(1234.555,"qqqq")=%%]</p>
<p>c19 expect=[-1234.555] got=[%%=FormatNumber(-1234.555,"0000")=%%]</p>
<p>c20 expect=[-1234.555] got=[%%=FormatNumber(-1234.555,"###0")=%%]</p>
<p>c21 expect=[-1234.555] got=[%%=FormatNumber(-1234.555,"#0.00")=%%]</p>
<p>c22 expect=[1234.555] got=[%%=FormatNumber(1234.555,"#,##0.00")=%%]</p>
<p>c23 expect=[-1234.555] got=[%%=FormatNumber(-1234.555,"#0.00;(#0.00)")=%%]</p>
<p>c24 expect=[4] got=[%%=FormatNumber(3.5,"N0")=%%]</p>
<p>c25 expect=[1.00] got=[%%=FormatNumber(1.005,"N2")=%%]</p>
<p>c26 expect=[1.00] got=[%%=FormatNumber(1.004,"N2")=%%]</p>
<p>c27 expect=[-2] got=[%%=FormatNumber(-2.5,"N0")=%%]</p>
<p>c28 expect=[-1,234.56] got=[%%=FormatNumber(-1234.555,"N2")=%%]</p>
<p>c29 expect=[-$1,234.56] got=[%%=FormatNumber(-1234.555,"C2")=%%]</p>
<p>c30 expect=[1,234.56] got=[%%=FormatNumber(1234.555,"N2","en-US")=%%]</p>
<p>c31 expect=[1,234.56] got=[%%=FormatNumber(1234.555,"N2","en_US")=%%]</p>
<p>c32 expect=[1 234,56] got=[%%=FormatNumber(1234.555,"N2","fr-FR")=%%]</p>
<p>c33 expect=[1,234.56] got=[%%=FormatNumber(1234.555,"N2","ja-JP")=%%]</p>
<p>c34 expect=[1,234.56] got=[%%=FormatNumber(1234.555,"N2","hi-IN")=%%]</p>
<p>c35 expect=[1.234,56] got=[%%=FormatNumber(1234.555,"N2","de")=%%]</p>
<p>c36 expect=[1,234.56] got=[%%=FormatNumber(1234.555,"N2","zz-ZZ")=%%]</p>
<p>c37 expect=[1,234.56] got=[%%=FormatNumber(1234.555,"N2","")=%%]</p>
<p>c38 expect=[1.234,56 €] got=[%%=FormatNumber(1234.555,"C2","de-DE")=%%]</p>
<p>c39 expect=[¥1,235] got=[%%=FormatNumber(1234.555,"C","ja-JP")=%%]</p>
<p>c40 expect=[1,234.56] got=[%%=FormatNumber("1234.555","N2")=%%]</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 save is rejected (HTTP 400) -->
%%[ SET @r2fne1 = 1234.555 ]%%%%=FormatNumber(@r2fne1)=%%
Differs from official docs
- Halves round to the even digit. The docs present rounding without naming the rule; their example rounds a trailing 5 up. In Next, with
N0,2.5gave2,-2.5gave-2and3.5gave4. Card PandEgive shapes the page does not show. Without a precision digit,Pgave three decimals (123,455.500%) andEgave1.234555E03. Card- Localised output uses non-ASCII characters. The docs show the German currency result with a plain space. Next puts U+00A0 before the euro sign, U+202F between French groups and the full-width
¥forja-JP. Card
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
Engagement rounds halves away from zero (FormatNumber(2.5,"N0") gives 3); Next rounds to the even digit (2). Engagement applies custom patterns (#,##0.00 gives 1,234.56) and echoes an unknown pattern (qqqq); Next returns the number unchanged (1234.555) in both cases. P, E and a negative C2 also differ: 123,455.50%, 1.234555E+003 and ($1,234.56) in Engagement, 123,455.500%, 1.234555E03 and -$1,234.56 in Next. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
- FormatCurrency — currency with the symbol chosen by the locale
- Format — numbers and dates
- FormatDate — dates only
- Official reference