fromFormat

Parses a display-formatted number into an Arith value using the active format settings.

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

Arith.fromFormat("$1,234,567.89", { prefix: "$" }).toString(); // "1234567.89"

// Parse a value with explicit display-format options.
Arith.fromFormat("1 234,56 EUR", {
  suffix: " EUR",
  groupSeparator: " ",
  decimalSeparator: ",",
}).toString(); // "1234.56"

// If options omit a field, the constructor FORMAT setting provides the fallback.
const Money = Arith.clone({
  FORMAT: { prefix: "$", groupSeparator: ",", decimalSeparator: "." },
});
Money.fromFormat("$9,876.50").toString(); // "9876.5"

API Reference

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.

Throws

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

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

Agent Notes

  • Pair fromFormat with the same format settings used by toFormat for reliable round trips.
  • Import with import { Arith } from "@teakit/arith"; default imports are unsupported.
  • 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.