Money talks, but can’t spell…

Peter MerrittFunLeave a Comment

It is well known that computers are superb at handling numbers (and before anyone raises it, even spelling and other nifty Word-processing tools are reduced to numeric rules and ‘weightings’; sorry…). However, for arcane reasons dating back well over two hundred years, some contractual statements of financial amounts must also be expressed in written English, presumably because potential 18thC fraudsters could add ok but not spell – actually a reasonable assumption if you’ve seen some documents from that time… History? No; one area of 21stC life is still bound by this – namely, writing cheques. So our systems must be capable of this as well.

Problem Specification

  1. Write a routine which converts a given number to correct ‘cheque-speak’;
  2. Pence should be included, although they’re easy, so almost irrelevant to the main problem;
  3. It must also use correct punctuation, and so read aloud exactly as a normal check;
  4. Minimum range is millions, but maximum range is Trillions – although once you have a solution it should be scalable.

Examples

  • 1233.11 = One thousand, two-hundred and thrity-three pounds (and eleven pence);
  • 100900003.00 = One hundred million, nine-hundred thousand, and three pounds;
  • 5712000054 = Five billion, seven-hundred and twelve million, and fifty-four pounds.

Hints

  • It is possible of course to have a several trillion element look-up table – but speed and storage is a bit problematic (and is totally inelegant; try again);
  • However, you should see a degree of repetition in how ranges of numbers are handled; this is what we are after.