The toPrecision helper formats a number to a specified number of significant digits. When the integer part of the number exceeds the precision, the output switches to scientific notation automatically. Use it when you need to control the total number of significant digits in a numeric output rather than just the decimal places.
Syntax
{{toPrecision field precision}}
field -- The numeric value to format. Required. Accepts a number, numeric string, or field reference. Non-numeric values return NaN.
precision -- The number of significant digits to include in the output. Required. Setting this too low (e.g. 1 or 2) pushes moderate numbers into scientific notation.
Examples
Switch between decimal and scientific notation
{{toPrecision 123.00 2}}
Output: 1.2e+2
{{toPrecision 123.00 3}}
Output: 123
When the integer part fits within the specified precision, the output uses standard decimal notation. When it doesn't, the output switches to scientific notation.
Format larger numbers
{{toPrecision 123456 5}}
Output: 1.2346e+5
{{toPrecision 1234567.00 6}}
Output: 1.23457e+6
Return raw output with triple braces
{{{toPrecision record.total 4}}}
Returns the formatted result without Celigo's automatic string wrapping. For example, record.total of 9876 returns 9876 and record.total of 9876.5 returns 9877.
Usage notes
-
toPrecisioncontrols the total number of significant digits, not just decimal places. Use toFixed helper to control decimal places instead. - When
precisionis lower than the number of integer digits, the output switches to scientific notation. - Non-numeric inputs return
NaN. - Use triple braces (
{{{ }}}) for raw output and double braces ({{ }}) when Celigo's default formatting is acceptable.