@ma.vu/app-money - v0.1.2
    Preparing search index...

    Module Core

    Exact, dependency-free Money values, arithmetic, formatting, and wire codecs.

    CurrencyCode
    CurrencyDisplay
    CurrencyMismatch
    DecimalWire

    { "amount": "12.50", "currency": "CHF" } (also accepts a JSON number)

    DecodeError
    Err
    InvalidAllocation
    InvalidAmount
    MinorWire

    { "amount": 1250, "currency": "CHF" } (integer minor units)

    Money
    MoneyError
    Ok
    Result
    Rounding
    CURRENCY_CODES
    abs
    add
    allocate

    Fowler's allocation: split an amount by ratios so the parts sum exactly to the original. The remainder (at most one minor unit per part) is handed out left to right.

    compare
    decodeDecimalWire
    decodeMinorWire
    describeError

    Human-readable message for logging / dev tooling.

    equals
    err
    flatMap
    format

    Locale-aware formatting via Intl. de-CH gives "CHF 1’234.50", bs-BA gives "1.234,50 KM", en-US gives "$1,234.50". locale must be a valid BCP 47 tag; it comes from your own config, not from the network, so a bad one is a programming error, not a runtime one.

    fromDecimal

    Parse a decimal amount. Prefer strings from the wire; a number is accepted but anything that isn't representable exactly (0.1 + 0.2, 1e21) is rejected rather than silently rounded.

    fromMinor
    isCurrencyCode
    isMoney

    Structural guard for the rare place that receives a Money as unknown (e.g. a schema adapter).

    isNegative
    isPositive
    isZero
    map
    minorDigits
    multiply

    Scale by a factor (VAT, discount, exchange rate). The result is rounded to a minor unit with round; Math.round is half-up toward +infinity, which is what most invoices expect. Pass Math.floor / Math.ceil or your own for other policies. For splitting an amount into parts use allocate, which never loses a minor unit.

    negate
    ok
    subtract
    sum
    toDecimal

    Float for display libraries only (Intl). Never do math on this.

    toDecimalString

    Exact decimal string, e.g. "-1234.50". Use this for the wire and for inputs.

    toDecimalWire
    toMinorWire
    zero