toFixed

Returns a fixed-point decimal string.

Human Summary

Use it for stable machine-readable fixed decimal output, especially money-like values.

AI Contract

FieldValue
Kindinstance method
Canonical nametoFixed
AliasesNone
Mutates receiverNo
Returnsstring
Accepts (string, base) overloadNo
Configuration dependenciesROUNDING_MODE
Related methodstoFormat, toPrecision, decimalPlaces

Signature

toFixed(decimalPlaces?: number, roundingMode?: ArithRoundingMode): string;

Parameters

ParameterTypeRequiredNotes
decimalPlacesnumberNoDigits after the decimal point. Negative values round left of the decimal point.
roundingModeArithRoundingModeNoDefaults to current ROUNDING_MODE.

Returns

Returns a string.

Behavior

  • Always uses normal fixed-point notation.
  • Pads trailing zeros when decimalPlaces requires them.
  • Rounds using the supplied mode or current ROUNDING_MODE.

Examples

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

new Arith("1.2").toFixed(2); // "1.20"
new Arith("1.235").toFixed(2); // "1.24"

Errors

  • Throws if decimalPlaces 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