Task

Show how to spell out a number in English.

You can use a preexisting implementation or roll your own, but you should support inputs up to at least one million (or the maximum value of your language's default bounded integer type, if that's less).

Support for inputs other than positive integers (like zero, negative integers, and floating-point numbers) is optional.



Related task

   Spelling of ordinal numbers.


 
  [ [ table
      $ "zero"  $ "one"   $ "two"
      $ "three" $ "four"  $ "five"
      $ "six"   $ "seven" $ "eight"
      $ "nine"  $ "ten"   $ "eleven"
      $ "twelve"   $ "thirteen"
      $ "fourteen" $ "fifteen"
      $ "sixteen"  $ "seventeen"
      $ "eighteen" $ "nineteen" ] do ]  is units   ( n --> $ )
 
  [ [ table
      $ "nonety" $ "tenty"   $ "twenty"
      $ "thirty" $ "fourty"  $ "fifty"
      $ "sixty"  $ "seventy" $ "eighty"
      $ "ninety" ] do ]                 is tens    ( n --> $ )
 
  [ $ "" swap
    dup 99 > if
      [ 100 /mod swap units
        $ " hundred" join
        swap dip join
        dup 0 = iff drop ]done[ ]
    over size 0 > if
      [ dip [ $ " and " join ] ]
    dup 19 > if
      [ 10 /mod swap tens
        swap dip join
        dup 0 = iff drop ]done[ ]
    over size 0 > if
      [ over -1 peek space != if
          [ dip [ space join ] ] ]
    units join ]                        is triplet ( n --> $ )
 
  [ $ "" swap
    dup 999999 > if
      [ 1000000 /mod swap triplet
        $ " million" join
        swap dip join
        dup 0 = iff drop ]done[ ]
    dup 999 > if
      [ over size 0 > if
          [ dip [ $ ", " join ] ]
        1000 /mod swap triplet
        $ " thousand" join
        swap dip join
        dup 0 = iff drop ]done[ ]
    over size 0 > if
      [ dip [ $ ", " join ] ]
    triplet join ]                      is name$   ( n --> $ )
 
   10 times
     [ 10 9 random 
       1+ ** random
       dup echo
       say " is:"
       name$ nest$ 
       60 wrap$ cr cr ]
 