toFixed

Formats the receiver as a fixed-point decimal string.

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

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

x.toFixed(); // "3.456"
x.toFixed(2); // "3.46"
x.toFixed(2, Arith.ROUND_DOWN); // "3.45"
x.toFixed(5); // "3.45600"

// Negative decimalPlaces round digits to the left of the decimal point.
const z = Arith.from("1234.5");
z.toFixed(-1); // "1230"
z.toFixed(-2); // "1200"
z.toFixed(-3); // "1000"

API Reference

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.

Throws

  • Throws if decimalPlaces or roundingMode is invalid.

Agent Contract

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

Agent Notes

  • 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.