sd

Getter/setter-style method for significant digits.

Human Summary

Call with no numeric argument to inspect significant digits, or with a number to round by significant digits.

AI Contract

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

Signature

sd(includeZeros?: boolean): number | null;
sd(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.

Behavior

  • Without numeric significantDigits, returns the number of significant digits or null for non-finite values.
  • When includeZeros is true, integer-part trailing zeros are counted.
  • With numeric significantDigits, returns a rounded copy.

Examples

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

new Arith("1000").sd(); // 1
new Arith("1000").sd(true); // 4
new Arith("9876").sd(3).toString(); // "9880"

Errors

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

Agent Notes

  • Disambiguate getter mode from rounding mode by checking whether the first argument is a number.
  • 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