There appears to be no way to render a number with thousands separators, a fixed number of decimal
places, or a currency symbol.
What I tried
All of these fail with a runtime error, which for a non-existent function is indistinguishable from
a bad argument (see the separate issue about empty error messages):
FORMAT(1234567.5) FORMAT(1234567.5, "#,##0.00")
FORMATNUMBER(1234567.5) NUMBERFORMAT(1234567.5)
FIXED(1234567.5, 2) FORMATCURRENCY(1234567.5)
CURRENCYFORMAT(1234567.5) CURRENCY(1234567.5)
TOSTRING(1234567.5)
What does work:
expression.Evaluator.run('TEXT(1234567.5)', someId); // => 1234567.5
expression.Evaluator.run('ROUND(1234567.5, 0)', someId); // => 1234568
So a number can be rounded, and it can be turned into a string, but the string has no grouping and
no way to force two decimals.
Why it matters
Any output a person reads — an invoice total, a pipeline rollup, a report line — wants
$1,234,567.50 and can only get 1234567.5. ROUND gets rid of ragged decimals but cannot add
grouping or pad to two places, so 1234567.5 and 1234567.50 are not distinguishable and a total
ending in .50 prints as .5.
Salesforce's own formula language has the same gap, so this may well be deliberate — but Expression
already goes well beyond formulas elsewhere, and DATETIMEFORMAT sets the precedent for a
pattern-based formatter.
Suggestion
A FORMATNUMBER(value, pattern) mirroring DATETIMEFORMAT(value, pattern) would cover it, with
the pattern passed to Apex's own number formatting. Currency symbol and grouping then fall out of
the pattern rather than needing a separate function.
Environment
Expression 1.52.0.1, Developer Edition scratch org.
There appears to be no way to render a number with thousands separators, a fixed number of decimal
places, or a currency symbol.
What I tried
All of these fail with a runtime error, which for a non-existent function is indistinguishable from
a bad argument (see the separate issue about empty error messages):
What does work:
So a number can be rounded, and it can be turned into a string, but the string has no grouping and
no way to force two decimals.
Why it matters
Any output a person reads — an invoice total, a pipeline rollup, a report line — wants
$1,234,567.50and can only get1234567.5.ROUNDgets rid of ragged decimals but cannot addgrouping or pad to two places, so
1234567.5and1234567.50are not distinguishable and a totalending in
.50prints as.5.Salesforce's own formula language has the same gap, so this may well be deliberate — but Expression
already goes well beyond formulas elsewhere, and
DATETIMEFORMATsets the precedent for apattern-based formatter.
Suggestion
A
FORMATNUMBER(value, pattern)mirroringDATETIMEFORMAT(value, pattern)would cover it, withthe pattern passed to Apex's own number formatting. Currency symbol and grouping then fall out of
the pattern rather than needing a separate function.
Environment
Expression 1.52.0.1, Developer Edition scratch org.