Functional Weave
Code in Python

banking.cheque-amount-words@1.0.0

README.md

1,731 bytes · view raw

# banking.cheque-amount-words

The two amount lines of a cheque: the words ("One thousand two hundred and
thirty-four pounds and fifty-six pence only") and the figures ("£1,234.56").

It does not spell numbers itself. The words are `text.number-to-words`
(`amountInWords`), so the British "and" rules, singular "one penny" and the
supported currencies are exactly that capability's; the figures are
`money.format`. What this adds is the cheque convention around them.

## Conventions

- The words line starts with a capital and ends with "only", the traditional
  guard against words being added after the amount.
- `penceStyle` `words` spells the pence out; `figures` writes them as a
  number with "p" (GBP) or "c" (EUR, USD): "One hundred and twenty pounds and
  50p only". Many UK cheque writers and banks' own guidance use the figures
  style; both are valid. Single pence are not padded: "and 5p".
- Whole amounts leave the pence out in both styles: "Ten pounds only".
- In the figures style the pounds are always in words, even when there are
  none ("Zero pounds and 50p only"), so the line never starts with a figure
  that could be altered. In the words style an amount under a pound reads
  "Fifty pence only", as `text.number-to-words` writes it.

## Edge cases

- The amount must be greater than zero: a cheque cannot be written for
  nothing or for a negative sum. (`text.number-to-words` accepts negatives for
  credit notes; this does not.)
- GBP, EUR and USD only, because those are the currencies
  `text.number-to-words` has unit names for; anything else fails with its
  error ("no words for currency").
- US checks conventionally write cents as a fraction ("and 99/100 dollars");
  that style is not offered.