toJSON

Returns the same string form as valueOf() and is used by JSON.stringify.

Summary

Use it implicitly through JSON.stringify when serializing Arith values.

AI Contract

FieldValue
Kindinstance method
Canonical nametoJSON
AliasesNone
Mutates receiverNo
Returnsstring
Accepts (string, base) overloadNo
Configuration dependenciesEXPONENTIAL_AT
Related methodsvalueOf, toString

Signature

toJSON(): string;

Parameters

ParameterTypeRequiredNotes
None--This method does not take parameters.

Returns

Returns a string.

Behavior

  • Includes the sign for negative zero.
  • Does not accept a base argument.
  • JSON.stringify calls this method automatically.

Examples

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

JSON.stringify({ total: new Arith("0.3") }); // "{\"total\":\"0.3\"}"

Errors

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

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