Runtime verified Differs from official docs Test scripts included

Syntax

FormatCurrency(value, locale[, decimalPlaces, symbol])  →  string
2–4 arguments

Parameters

Name Type Required Description
value string | number Yes Amount to format; a numeric string works and may carry thousands separators
locale string Yes Locale supplying the symbol, its position and the separators; hyphen or underscore
decimalPlaces string | number No Overrides the locale’s own decimal count
symbol string No Replaces the symbol only; the locale still decides where it goes

In Next the email saves with decimalPlaces and symbol, but neither changes the output. The locale alone decides the decimals and the symbol.

Example

%%=FormatCurrency(1234.555, "en-US")=%%

Renders $1,234.56.

The same amount for a German reader:

%%=FormatCurrency(1234.555, "de-DE")=%%

Renders 1.234,56 €, with a non-breaking space (U+00A0) before the euro sign.

Return value

string — the amount as currency for the locale.

The result is open text. With an empty or unknown locale the input comes back unformatted.

Behaviour

The locale decides the symbol, its position, the separators and the decimals. Each row below is 1234.555 with only a locale:

Locale Result Notes
en-US $1,234.56  
en_US $1,234.56 underscore form accepted
en-GB £1,234.56  
de-DE 1.234,56 € U+00A0 before the symbol
fr-FR 1 234,56 € U+202F as group separator, U+00A0 before the symbol
pt-BR R$ 1.234,56 U+00A0 after the symbol
hi-IN ₹1,234.56  
de-CH CHF 1’234.56 U+00A0 after the symbol, U+2019 as group separator
ja-JP ¥1,235 full-width yen sign U+FFE5, no decimals
de 1.234,56 ¤ generic currency sign U+00A4
zz-ZZ 1234.555 unformatted
"" 1234.555 unformatted

Several of these contain characters other than a plain space or apostrophe, so a comparison written against ASCII text will not match.

The decimal count has no effect. de-DE with 3 gives 1.234,56 €, de-CH with 0 gives CHF 1’234.56, ja-JP with 2 gives ¥1,235, and en-US with "3" gives $1,234.56.

The symbol argument has no effect. es-MX with "Mex$" gives $1,234.56; de-DE with "CHF" gives 1.234,56 €.

Halves round to the even digit. 2.345 gives $2.34, while 2.355 gives $2.36 and 1234.555 gives $1,234.56.

Negatives get a minus sign. -1234.555 gives -$1,234.56 for en-US and -1.234,56 € for de-DE.

A numeric string works like the number. "1234.555" gives $1,234.56, "1234.5" gives $1,234.50.

The locale is required. An email with FormatCurrency(@amount) 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 FormatCurrency. 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=[%%=FormatCurrency("1234.5","en-US")=%%]</p>
<p>c2 expect=[$1,234.56] got=[%%=FormatCurrency(1234.555,"en-US")=%%]</p>
<p>c3 expect=[1.234,56 €] got=[%%=FormatCurrency(1234.555,"de-DE")=%%]</p>
<p>c4 expect=[$2.34] got=[%%=FormatCurrency(2.345,"en-US")=%%]</p>
<p>c5 expect=[£1,234.56] got=[%%=FormatCurrency(1234.555,"en-GB")=%%]</p>
<p>c6 expect=[1 234,56 €] got=[%%=FormatCurrency(1234.555,"fr-FR")=%%]</p>
<p>c7 expect=[R$ 1.234,56] got=[%%=FormatCurrency(1234.555,"pt-BR")=%%]</p>
<p>c8 expect=[₹1,234.56] got=[%%=FormatCurrency(1234.555,"hi-IN")=%%]</p>
<p>c9 expect=[CHF 1’234.56] got=[%%=FormatCurrency(1234.555,"de-CH")=%%]</p>
<p>c10 expect=[¥1,235] got=[%%=FormatCurrency(1234.555,"ja-JP")=%%]</p>
<p>c11 expect=[¥1,235] got=[%%=FormatCurrency(1234.555,"ja-JP",2)=%%]</p>
<p>c12 expect=[$1,234.56] got=[%%=FormatCurrency(1234.555,"en_US")=%%]</p>
<p>c13 expect=[1.234,56 ¤] got=[%%=FormatCurrency(1234.555,"de")=%%]</p>
<p>c14 expect=[1234.555] got=[%%=FormatCurrency(1234.555,"")=%%]</p>
<p>c15 expect=[1234.555] got=[%%=FormatCurrency(1234.555,"zz-ZZ")=%%]</p>
<p>c16 expect=[1.234,56 €] got=[%%=FormatCurrency(1234.555,"de-DE",3)=%%]</p>
<p>c17 expect=[$1,234.56] got=[%%=FormatCurrency(1234.555,"en-US","3")=%%]</p>
<p>c18 expect=[CHF 1’234.56] got=[%%=FormatCurrency(1234.555,"de-CH",0)=%%]</p>
<p>c19 expect=[$1,234.56] got=[%%=FormatCurrency(1234.555,"es-MX",2,"Mex$")=%%]</p>
<p>c20 expect=[1.234,56 €] got=[%%=FormatCurrency(1234.555,"de-DE",2,"CHF")=%%]</p>
<p>c21 expect=[$2.36] got=[%%=FormatCurrency(2.355,"en-US")=%%]</p>
<p>c22 expect=[-$1,234.56] got=[%%=FormatCurrency(-1234.555,"en-US")=%%]</p>
<p>c23 expect=[-1.234,56 €] got=[%%=FormatCurrency(-1234.555,"de-DE")=%%]</p>
<p>c24 expect=[$1,234.56] got=[%%=FormatCurrency("1234.555","en-US")=%%]</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 @r2fce1 = 1234.555 ]%%%%=FormatCurrency(@r2fce1)=%%

Differs from official docs

  • The decimals and symbol arguments are ignored. The docs show the third argument changing the decimals and the fourth replacing the symbol (Mex$). In Next, de-CH with 0 still gave two decimals, ja-JP with 2 still gave none, and Mex$ gave $1,234.56. Card
  • The output uses non-ASCII characters. The docs write their samples with plain spaces, a plain apostrophe and ¥. Next uses U+00A0 and U+202F spaces, U+2019 for the Swiss group separator and the full-width ¥. Card
  • Rounding and unknown locales are not covered by the docs. In Next 2.345 gives $2.34, rounded down although the docs show no rule (whether the binary representation or rounding halves to the even digit causes it was not isolated); an empty or unknown locale returns the raw number, and de gives the generic ¤ sign. Card

Availability & differences

PlatformAvailable
Marketing Cloud EngagementYes
Marketing Cloud NextYes, from API 67.0

See also