dp

Getter/setter-style method for decimal places.

Human Summary

Call without arguments to inspect scale, or with a number to round a value to decimal places.

AI Contract

FieldValue
Kindinstance method
Canonical namedecimalPlaces
AliasesdecimalPlaces
Mutates receiverNo
Returns`number
Accepts (string, base) overloadNo
Configuration dependenciesROUNDING_MODE
Related methodsdecimalPlaces, integerValue

Signature

dp(): number | null;
dp(decimalPlaces: number, roundingMode?: ArithRoundingMode): ArithInstance;

Parameters

ParameterTypeRequiredNotes
decimalPlacesnumberNoWhen provided, round to this many decimal places.
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 decimalPlaces, returns the number of decimal places or null for non-finite values.
  • With decimalPlaces, returns a rounded copy.
  • decimalPlaces may be negative, which rounds to digits left of the decimal point.

Examples

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

new Arith("1.2345").dp(); // 4
new Arith("1.235").dp(2).toString(); // "1.24"

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