Functional Weave
Code in Python

text.number-to-words@1.0.0

README.md

2,088 bytes · view raw

# text.number-to-words

Writes a money amount the way it goes on a cheque or a remittance advice:
123456 pence is "one thousand two hundred and thirty-four pounds and
fifty-six pence". The number words come from `text.integer-to-words`, so the
British "and" rules are the same in both: "one hundred and one pounds", "one
thousand and one pounds".

## Why it takes Money

A cheque amount is money, and money in this registry is never a float.
Taking `Money` (integer minor units) means 0.1 + 0.2 can never turn into
"thirty pence and a bit", and the pence are always exactly what was paid.

## Wording

- Major units, then " and ", then minor units: "one pound and one penny".
- Singular for exactly one: "one pound", "one penny", "one euro", "one cent",
  "one dollar". Otherwise plural: "pounds", "pence", "euros", "cents",
  "dollars".
- A whole amount leaves the minor units out: "ten pounds", not "ten pounds and
  zero pence". An amount under one major unit leaves the major units out:
  "fifty pence". Zero is "zero pounds".
- No "only" is added. Cheque writers traditionally end with "only" to stop
  words being added afterwards; append it yourself if your stationery wants it.
- Negative amounts (credit notes) read as "minus ...".
- Everything is lower case.

## Currencies

Only the three currencies whose English unit names are listed below are
supported; any other currency is an error, not a guess, because the words for
a currency's units are not derivable from its code.

| Code | Major (one / many) | Minor (one / many) |
|------|--------------------|--------------------|
| GBP  | pound / pounds     | penny / pence      |
| EUR  | euro / euros       | cent / cents       |
| USD  | dollar / dollars   | cent / cents       |

All three have two decimal places. EU legislation spells the plural "euro"
with no "s" in English; everyday British and Irish usage, and most invoices,
say "euros", which is what this writes.

## Limits

The amount's minor units must be within 2^53 - 1 (the range all three
languages agree on); `text.integer-to-words` rejects anything larger.