Skip to content
@deckyard/money

money cheatsheet

Every export of @deckyard/money. Guides are listed in the introduction.

jennifer
import "@deckyard/money/" as money;

Every failure is Error{kind: "money"}. A code is an ISO 4217 code such as "EUR"; a mode is one of MODES. Factors, rates and ratios are decimal strings such as "1.19".

Constants

ConstantValueMeaning
ERROR_KIND"money"the kind of every error the deck throws
MODES["half-even", "half-up", "half-down", "up", "down", "ceiling", "floor"]the rounding modes
MAX_TEXT50the longest amount, factor, rate or ratio string
MAX_PARTS100000the most parts allocate and allocateTo make

Types

Money

FieldMeaning
amount as intminor units: 1234 for 12.34 EUR
currency as stringthe ISO 4217 code

Making and reading

FunctionReturnsDoes
money.fromMinor(amount, code)Moneyan amount of minor units
money.zero(code)Moneyzero
money.parse(text, code)Moneyread "12.34"; extra places only if zeros
money.format(m)string"12.34", "1200" for JPY
money.fromDecimal(d, code, mode)Moneya decimal in major units, rounded
money.toDecimal(m)decimal.Decimalthe amount in major units

Currencies

FunctionReturnsDoes
money.isCurrency(code)boolwhether the code is in the table
money.digits(code)intthe minor units: 0, 2, 3 or 4
money.currencies()list of stringevery code, sorted
money.published()stringthe date of the ISO 4217 list used

Arithmetic

FunctionReturnsDoes
money.add(a, b)Moneya + b
money.subtract(a, b)Moneya - b
money.sum(ms, code)Moneythe total of a list; zero when empty
money.negate(m)Money-m
money.absolute(m)Money|m|
money.multiply(m, factor, mode)Moneym * factor, rounded
money.divide(m, divisor, mode)Moneym / divisor, rounded
money.allocate(m, ratios)list of Moneysplit by ratios; the parts sum to m
money.allocateTo(m, n)list of Moneysplit into n equal parts
money.exchange(m, code, rate, mode)Moneyinto another currency at rate, rounded

Comparing

FunctionReturnsDoes
money.compare(a, b)int-1, 0 or 1
money.lessThan(a, b)boola < b
money.greaterThan(a, b)boola > b
money.isZero(m)boolm == 0
money.isNegative(m)boolm < 0
money.isPositive(m)boolm > 0

The currencies module

import "@deckyard/money/currencies.j" as currencies; reads the table itself. It is generated; see Currencies.

ConstantValueMeaning
currencies.PUBLISHED"2026-09-17"the date of the ISO 4217 list
currencies.DIGITS{"AED": 2, ...}each code's minor units