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.
number– format a number usingformatand optionalsetLangnumber0– same asnumber, but returns0when input is undefined
Simple / Easy Usage (No Format or Language)
The easiest way to format a number is to use just the value – no format or language variables needed. It will use the default format 0,0.00 (thousands separator with 2 decimals) and en-US locale.
Examples
Result: 9,876,543.21
How do I add commas and a decimal point to a number?
Use the number helper — you can rely on the default behavior (no extra parameters) or specify the 0,0.00 format explicitly to ensure commas for thousands and two decimal places.
Result: 9,876,543.21
If you prefer to be explicit (same output):
Result: 9,876,543.21
Result: 123,456,789.00
Function name meaning (quick reference)
number(thisNumber, format, setLang)= format a numeric valuenumber0(thisNumber, format, setLang)= format a numeric value, with0fallback for undefined inputformat= numeric format pattern string (optional)setLang= language code used by formatter (optional, default:en-US)
Note: Both
formatandsetLangare optional. If you omit them, the helper uses the default format0,0.00and languageen-US.
number
Formats a number using a format pattern.
From implementation behavior:
- If
thisNumberisundefined, returns empty string - If
formatis not a string, defaults to0,0.00 - If
setLangis not provided, defaults toen-US
Expected result: 1,234,567.80
number0
Formats a number the same way as number, but when input is undefined it returns 0.
Expected result: 0 (when field is undefined)
Format examples
Use different patterns depending on display needs.
Two decimals with separators
Expected result: 9,876,543.21
Integer with separators
Expected result: 9,876,543
Fixed 3 decimals
Expected result: 52.700
Practical end-to-end example
Best Practices
- Always pass an explicit format string for consistent output.
- Keep language code explicit when templates are shared across regions.
- Use
number0when you prefer fallback0for 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:
Result: 9,876,543.21
How do I display a whole number without decimals?
Use the 0,0 format pattern:
Result: 9,876,543
How do I show a value as 0 when a field is undefined?
Use number0 instead of number:
Result: 0 (when field is missing)
How do I format numbers for different languages?
Change the language code in the third parameter:
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: