Functional Weave
Code in Rust

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

  • currency_digits(GBP) → 2 pound sterling has two
  • currency_digits(EUR) → 2 euro has two
  • currency_digits(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.

pub fn currency_digits(currency: &str) -> i64
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

fune!(money.currency-digits@^1);  // then call currency_digits(…)
impl/rust.rs · 20 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.

use super::funejson::Value;  ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::money_currency_digits_data::CURRENCY_DIGITS;  ← 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.
///
/// # Panics
/// Panics if the code is not an active ISO 4217 currency with a minor unit.
pub fn currency_digits(currency: &str) -> i64 {
    match CURRENCY_DIGITS.iter().find(|c| c.code == currency) {
        Some(row) => row.digits,
        None => panic!("no ISO 4217 minor unit for currency \"{}\"", currency),
    }
}

pub fn fune_vector(args: &[Value]) -> Value {
    Value::Int(currency_digits(args[0].as_str()))
}

Install

fune build

With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the Rust 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. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:

fune add money.currency-digits
Download for Rust money.currency-digits-1.0.0-rust.fune · 15,965 bytes sha256 05b8cca7bba2765fb8a9fe46eee48da38064c3eb9458502f0948aca052e5c54a

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

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