Differences between revisions 1 and 2
Revision 1 as of 2010-03-26 15:24:02
Size: 1017
Editor: SimonMarsden
Comment:
Revision 2 as of 2010-03-26 15:32:21
Size: 1021
Editor: SimonMarsden
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Can you write a function which spells out numbers as words. For example, 108 becomes "One hundred and eight". Can you write a function which spells out whole numbers as words? For example, 108 becomes "One hundred and eight".

Spelling Numbers in Words

Can you write a function which spells out whole numbers as words? For example, 108 becomes "One hundred and eight".

For the sake of the puzzle you should make sure that your solution handles the following

  • Negative numbers should be preceded by a "Minus", e.g. "Minus seventeen"
  • Use UK English usage of the word "and", e.g "One hundred and eight", not the US "One hundred eight"
  • Use commas after every group, e.g. "Two million, six hundred and sixteen thousand, eight hundred and one"
  • Standard use of a hyphen, e.g. "Twenty-six", "Two thousand, one hundred and twenty-six"

Examples:

      SpellNumber 0
Zero
      SpellNumber ¯8
Minus eight
      Spell Number 10001
Ten thousand and one
      Spell Number 1234567890
One billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety

>> The Solution

   

Author: SimonMarsden


CategoryPuzzles

SpellNumbers/Task (last edited 2010-03-26 15:32:21 by SimonMarsden)