Viewer Number Helpers
This page explains common number helpers you can use in Viewer templates.
Use these helpers to format and convert numeric values for cleaner document output.
Function name meaning (quick reference)
addCommas= format number with thousands separatorstoFixed= keep a fixed number of decimal placestoInt= convert value to an integertoFloat= convert value to a decimal numbertoPrecision= format number with significant digitstoExponential= show number in exponential notationbytes= format bytes into KB/MB/GB display
addCommas
Formats a number with comma separators.
Scenario: Show revenue in a readable format.
Expected result: 1,250,000
toFixed
Formats a number with fixed decimal places.
Scenario: Always show 2 decimals for pricing.
Expected result: 19.90
toInt
Converts a value to an integer.
Scenario: Remove decimals for rounded quantity display.
Expected result: 42
toFloat
Converts a value to float (decimal number).
Scenario: Ensure numeric decimal formatting for calculations.
Expected result: 42.88
toPrecision
Formats a number using significant digits.
Scenario: Display concise scientific or KPI values.
Expected result: 1235
toExponential
Converts a number to exponential notation.
Scenario: Show very large values in compact technical format.
Expected result: 1.25e+6
bytes
Formats byte values into readable units.
Scenario: Show file size in KB/MB instead of raw bytes.
Expected result: 1 MB
Practical end-to-end example
Number helper tips
- Use
addCommasfor user-facing amounts. - Use
toFixedfor currency-like values. - Use
toIntandtoFloatwhen field types are inconsistent. - Keep output format consistent across the same document.
Common Use Cases
How do I add comma separators to large numbers?
Use addCommas for readability:
Result: 1,250,000 instead of 1250000
How do I format prices with exactly 2 decimal places?
Use toFixed for currency:
Result: 19.99 (or 19.00 if value is 19)
How do I remove decimal places from a quantity?
Use toInt for whole numbers:
Result: 42 (from 42.88)
How do I handle fields that might be text instead of numbers?
Use toFloat to convert text to numbers:
Result: 42.88 (converts "42.88" string to number)
How do I format very large numbers compactly?
Use toExponential for scientific notation:
Result: 1.25e+6
How do I show file sizes in human-readable format?
Use bytes to format KB/MB:
Result: 2.5 MB (from 2621440 bytes)