fromFormat

Removes configured prefix, suffix, signs, grouping, and decimal separators, then constructs an Arith value.

Summary

Use this when users or external systems provide display-formatted numbers and you need a decimal value for calculation.

AI Contract

FieldValue
Kindstatic method
Canonical namefromFormat
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadNo
Configuration dependenciesFORMAT, STRICT
Related methodstoFormat, config

Signature

Arith.fromFormat(str: string, options?: ArithFormat): ArithInstance;

Parameters

ParameterTypeRequiredNotes
strstringYesFormatted numeric string to parse.
optionsArithFormatNoFormat overrides. Missing fields fall back to current FORMAT.

Returns

Returns a new Arith instance parsed from the formatted string.

Behavior

  • If options is omitted, current Arith.config().FORMAT is used.
  • Provided options are resolved against current FORMAT defaults.
  • Group separators are removed from the integer part.
  • Fraction group separators are removed from the fractional part.
  • The resulting plain numeric string is passed to the constructor.

Examples

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

const parsed = Arith.fromFormat("$1,234,567.89", { prefix: "$" });

parsed.toString(); // "1234567.89"

Errors

  • Throws if str is not a string.
  • Throws if options is provided but is not an object.
  • Throws if the normalized value is invalid while STRICT is true.

Agent Notes

  • Pair fromFormat with the same format settings used by toFormat for reliable round trips.
  • Import from @teakit/arith; prefer import { Arith } from "@teakit/arith".
  • Static helpers are called as Arith.method(...) and do not require an instance receiver.
  • Do not generate BigNumber, Decimal, isBigNumber, or isDecimal compatibility APIs.
  • Use string inputs for exact decimal values when a static helper accepts numeric values.

See Also