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.


 
DEFINE units ==
[ "zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten"
  "eleven" "twelve" "thirteen" "fourteen" "fifteen" "sixteen" "seventeen"
  "eighteen" "nineteen" ];
 
tens ==
[ "ten" "twenty" "thirty" "forty" "fifty" "sixty" "seventy" "eighty" "ninety" ];
 
convert6 ==
[1000000 <]
[1000 div swap convert " thousand " putchars convert3]
[1000000 div swap convert " million " putchars convert3]
ifte;
 
convert5 ==
[null]
[]
[" and " putchars convert]
ifte;
 
convert4 ==
[1000 <]
[100 div swap units of putchars " hundred" putchars convert5]
[convert6]
ifte;
 
convert3 ==
[null]
[]
[32 putch convert]
ifte;
 
convert2 ==
[100 <]
[10 div swap pred tens of putchars convert3]
[convert4]
ifte;
 
convert ==
[20 <]
[units of putchars]
[convert2]
ifte.
 