Skip to main content

Number Format Helper

This page explains the custom number and number0 helpers from your template helper library.

Use these helpers to format numeric values with a format pattern and language setting.

Quick Reference
  • number – format a number using format and optional setLang
  • number0 – same as number, but returns 0 when input is undefined

Function name meaning (quick reference)

  • number(thisNumber, format, setLang) = format a numeric value
  • number0(thisNumber, format, setLang) = format a numeric value, with 0 fallback for undefined input
  • format = numeric format pattern string
  • setLang = language code used by formatter (default: en-US)

number

Formats a number using a format pattern.

From implementation behavior:

  • If thisNumber is undefined, returns empty string
  • If format is not a string, defaults to 0,0.00
  • If setLang is not provided, defaults to en-US
Example: Field-based
{{number Opportunity.Amount "0,0.00" "en-US"}}
Example: Actual number
{{number 1234567.8 "0,0.00" "en-US"}}

Expected result: 1,234,567.80

number0

Formats a number the same way as number, but when input is undefined it returns 0.

Example: Field-based
{{number0 Quote.Total_Amount__c "0,0.00" "en-US"}}
Example: Undefined input fallback
{{number0 Undefined_Field__c "0,0.00" "en-US"}}

Expected result: 0 (when field is undefined)

Format examples

Use different patterns depending on display needs.

Two decimals with separators

Pattern: 0,0.00
{{number 9876543.21 "0,0.00" "en-US"}}

Expected result: 9,876,543.21

Integer with separators

Pattern: 0,0
{{number 9876543.21 "0,0" "en-US"}}

Expected result: 9,876,543

Fixed 3 decimals

Pattern: 0,0.000
{{number 52.7 "0,0.000" "en-US"}}

Expected result: 52.700

Practical end-to-end example

Invoice amount block
Subtotal: {{number Invoice.Subtotal__c "0,0.00" "en-US"}}
Tax: {{number Invoice.Tax__c "0,0.00" "en-US"}}
Total: {{number0 Invoice.Total__c "0,0.00" "en-US"}}

Best Practices

  • Always pass an explicit format string for consistent output.
  • Keep language code explicit when templates are shared across regions.
  • Use number0 when you prefer fallback 0 for undefined values.
  • Test formatting with real record data before publishing templates.

Common Use Cases

How do I format a number with thousands separators and 2 decimals?

Use the 0,0.00 format pattern:

{{number 9876543.21 "0,0.00" "en-US"}}

Result: 9,876,543.21

How do I display a whole number without decimals?

Use the 0,0 format pattern:

{{number 9876543.21 "0,0" "en-US"}}

Result: 9,876,543

How do I show a value as 0 when a field is undefined?

Use number0 instead of number:

{{number0 Quote.Total_Amount__c "0,0.00" "en-US"}}

Result: 0 (when field is missing)

How do I format numbers for different languages?

Change the language code in the third parameter:

{{number 1234567.89 "0,0.00" "de-DE"}}
{{number 1234567.89 "0,0.00" "fr-FR"}}

Result:

  • German: 1.234.567,89 (periods as thousands, comma as decimal)
  • French: 1 234 567,89 (spaces as thousands, comma as decimal)

How do I create an invoice with consistent number formatting?

Apply the same format to all numeric fields:

Subtotal: {{number Invoice.Subtotal__c "0,0.00" "en-US"}}
Tax: {{number Invoice.Tax__c "0,0.00" "en-US"}}
Total: {{number0 Invoice.Total__c "0,0.00" "en-US"}}

More resources