precision

Returns the significant-digit count or returns a copy rounded to a specified number of significant digits.

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

const x = Arith.from("9876.54321");

x.precision(6).toString(); // "9876.54"
x.precision(); // 9
x.precision(6, Arith.ROUND_UP).toString(); // "9876.55"
x.precision(2, Arith.ROUND_DOWN).toString(); // "9800"

// The receiver is not mutated.
x.toString(); // "9876.54321"

const y = Arith.from("987000");
y.precision(); // 3
y.precision(true); // 6

API Reference

Signature

precision(includeZeros?: boolean): number | null;
precision(significantDigits: number, roundingMode?: ArithRoundingMode): ArithInstance;

Parameters

ParameterTypeRequiredNotes
includeZerosbooleanNoGetter mode only. Include integer-part trailing zeros when true.
significantDigitsnumberNoWhen a number is provided, round to this many significant digits.
roundingModeArithRoundingModeNoDefaults to current ROUNDING_MODE.

Returns

In getter mode, returns a number or null for non-finite values. In rounding mode, returns a new Arith instance.

Throws

  • Throws if the numeric argument is outside its allowed range.
  • Throws if roundingMode is invalid.

Agent Contract

FieldValue
Kindinstance method
Canonical nameprecision
AliasesNone
Mutates receiverNo
Returns`number
Accepts (string, base) overloadNo
Configuration dependenciesROUNDING_MODE
Related methodsintegerValue

Agent Notes

  • precision is the only public API for significant-digit count and significant-digit rounding; do not generate sd.
  • Disambiguate getter mode from rounding mode by checking whether the first argument is a number.
  • Import with import { Arith } from "@teakit/arith"; default imports are unsupported.
  • Use Arith.from(...) to create values. Do not generate new Arith(...) or Arith(...).
  • 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.