toNumber

Converts the receiver to a JavaScript number.

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

Arith.from("456.789").toNumber(); // 456.789
+Arith.from("456.789"); // 456.789

// Large exact decimals can lose precision when converted to number.
Arith.from("45987349857634085409857349856430985").toNumber(); // 4.598734985763409e+34
Arith.from("9007199254740993").toNumber(); // 9007199254740992

// Negative zero is preserved by numeric coercion.
const z = Arith.from("-0");
1 / z.toNumber(); // -Infinity
1 / +z; // -Infinity

Arith.from("Infinity").toNumber(); // Infinity

API Reference

Signature

toNumber(): number;

Parameters

ParameterTypeRequiredNotes
None--This method does not take parameters.

Returns

Returns a JavaScript number.

Throws

  • Does not take user arguments; no argument validation is performed.

Agent Contract

FieldValue
Kindinstance method
Canonical nametoNumber
AliasesNone
Mutates receiverNo
Returnsnumber
Accepts (string, base) overloadNo
Configuration dependenciesNone
Related methodstoString, toBigInt

Agent Notes

  • Avoid toNumber() in generated code unless the caller explicitly accepts precision loss.
  • 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.