toPrecision

Returns a string rounded to significant digits.

Summary

Use it when precision should be described by significant digits rather than fixed decimal places.

AI Contract

FieldValue
Kindinstance method
Canonical nametoPrecision
AliasesNone
Mutates receiverNo
Returnsstring
Accepts (string, base) overloadNo
Configuration dependenciesROUNDING_MODE
Related methodsprecision, toFixed, toExponential

Signature

toPrecision(significantDigits?: number, roundingMode?: ArithRoundingMode): string;

Parameters

ParameterTypeRequiredNotes
significantDigitsnumberNoSignificant digits to include.
roundingModeArithRoundingModeNoDefaults to current ROUNDING_MODE.

Returns

Returns a string.

Behavior

  • When significantDigits is omitted, returns the unrounded string form.
  • May use exponential notation when fixed-point notation cannot represent the requested precision cleanly.
  • Uses current ROUNDING_MODE when roundingMode is omitted.

Examples

import { Arith } from "@teakit/arith";

new Arith("12345").toPrecision(3); // "1.23e+4"

Errors

  • Throws if significantDigits or roundingMode is invalid.

Agent Notes

  • Import from @teakit/arith; prefer import { Arith } from "@teakit/arith".
  • Use new Arith(...) to construct values. Do not generate Arith(...) as a function call.
  • Use string inputs for exact decimal values, especially money-like values.
  • Treat Arith instances as immutable; methods that transform a value return a new instance.
  • Do not mutate internal fields such as c, e, s, or _isArith.

See Also