Skip to content
1 min read · 161 words

Function: formatBig()

ts
function formatBig(value: number | BigNumber, precision?: number): string;

Defined in: lib/helpers/bignum.ts:72

Render a BigNumber (or JS number) to a string at precision significant digits.

Parameters

ParameterTypeDefault value
value| number | BigNumberundefined
precisionnumberDEFAULT_PRECISION

Returns

string

Remarks

  • An EXACT INTEGER is rendered in full fixed notation regardless of precision: an integer carries no fractional precision to lose, so 8000000000000 stays 8000000000000 rather than being truncated to 8e+12. (Bounded at 30 digits to avoid pathological astronomically-large integers printing thousands of characters; beyond that, sig-fig exponential is used.)
  • Non-integers are rendered at precision significant digits (default 8), stripping trailing zeros — avoiding the toPrecision artifact that mangled safe values, while still giving the caller control over how many digits they want (raise precision for more).
  • Exact zero renders as '0'. (Genuinely tiny values like 2.54e-5 are preserved, NOT snapped.)