Skip to content

No way to format a number: no thousands separators, fixed decimals or currency #248

Description

@cesarParra

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions