Functional Weave
Code in TypeScript

money.currency-digits

How many decimal places a currency's minor unit has, from the ISO 4217 list.

1.0.0 · published 2026-10-03 by charlie · Anterra

Pinned by 14 tests, run in TypeScript, Python and Rust.

What it does

The number of decimal places in a currency's minor unit: 2 for pounds and euros, 0 for yen and won, 3 for Kuwaiti and Bahraini dinar, 4 for the Chilean Unidad de Fomento. Anything that turns minor units into major units - parsing, converting, displaying - needs this, and dividing by 100 is wrong for about a sixth of the world's currencies.

The table in `data/currency-digits.json` is ISO 4217 List One as published by SIX Financial Information, the ISO 4217 maintenance agency, on 2026-09-17: every active currency code with a numeric minor unit (165 codes). Precious metals, fund codes and testing codes whose minor unit is "N.A." (XAU, XAG, XDR, XTS, XXX and the like) are left out, and asking for one is an error, as is any code not on the list. Codes are matched exactly, so `"gbp"` is an error rather than a guess.

For example

  • currencyDigits(GBP) → 2 pound sterling has two
  • currencyDigits(EUR) → 2 euro has two
  • currencyDigits(USD) → 2 US dollar has two

The function

The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.

export function currencyDigits(currency: string): number
currencystringISO 4217 alphabetic code, uppercase
returnsint0 for JPY, 2 for GBP, 3 for KWD, 4 for CLF

Your code names it in one line, in the file that uses it

import { currencyDigits } from "#fune/money.currency-digits@^1";
impl/typescript.ts · 15 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

import { CURRENCY_DIGITS } from "./money_currency_digits_data.ts";  ← this capability’s own data, compiled from data/currency-digits.json into the same file by fune build

/**
 * Decimal places in a currency's minor unit, per ISO 4217.
 *
 * Dividing by 100 is wrong for yen, won, dinar and a few dozen others, so
 * anything moving between minor and major units asks here.
 */
export function currencyDigits(currency: string): number {
  const row = CURRENCY_DIGITS.find((c) => c.code === currency);
  if (row === undefined) {
    throw new RangeError(`no ISO 4217 minor unit for currency "${currency}"`);
  }
  return row.digits;
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add money.currency-digits
Download for TypeScript money.currency-digits-1.0.0-typescript.fune · 15,787 bytes sha256 37d35cc8c27649dcf454192927ae26b1cdb1d9b2e27cb371f3e5734eedf93d20

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./money.currency-digits-1.0.0-typescript.fune, or fetch it from a terminal with fune pull money.currency-digits@1.0.0:typescript.

The whole function, every language, is one file too: money.currency-digits-1.0.0.fune, 17,054 bytes, sha256 b63fec1cb7b8064cbb5b61d7419482b8766fe76df16f4f73fdd7fd94af91de47. It installs into a project of any language.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

// fune: before money.currency-digits

after — your function gets the result and the arguments, and returns the final result.

// fune: after money.currency-digits

replace — it requires no other capability, so there is no dependency to replace.

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show money.currency-digits --steps.

// fune: step money.currency-digits after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.

CaseArgumentsExpected
pound sterling has two GBP → 2
euro has two EUR → 2
US dollar has two USD → 2
yen has none JPY → 0
won has none KRW → 0
Icelandic krona has none ISK → 0
Kuwaiti dinar has three KWD → 3
Bahraini dinar has three BHD → 3
Chilean Unidad de Fomento has four CLF → 4
Hungarian forint is two under ISO 4217 HUF → 2
Show the other 4 tests
CaseArgumentsExpected
CFA franc has none XOF → 0
gold has no minor unit and is an error XAU → error: no ISO 4217 minor unit
lowercase is not matched gbp → error: no ISO 4217 minor unit
an unknown code is an error, not two XYZ → error: no ISO 4217 minor unit

More from the author

Source: ISO 4217 Currency Code Maintenance, List One: Currency, fund and precious metal codes - https://www.six-group.com/dam/download/financial-information/data-center/iso-currrency/lists/list-one.xml (published 2026-09-17).

When ISO amends the list, publish a new version with the new table. The digits are what ISO says, not what a country's cash uses day to day: ISK and UGX are 0, HUF is 2 even though forint coins stopped at 1.

Files

PathBytes
README.md1,284
data/currency-digits.json9,276
impl/python.py485
impl/rust.rs713
impl/typescript.ts530
vectors.json1,093