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.


      DIM test%(20)
      test%() = 0, 1, 2, 19, 20, 21, 99, 100, 101, 300, 310, 1001, -1327, 1501, \
      \         10203, 12609, 101104, 102003, 467889, 1005006, -123000789
      FOR i% = 0 TO DIM(test%(),1)
        PRINT FNsaynumber(test%(i%))
      NEXT
      END
 
      DEF FNsaynumber(n%)
      LOCAL number%(), number$(), i%, t%, a$
      DIM number%(29), number$(29)
      number%() = 1000000000, 1000000, 1000, 100, 90, 80, 70, 60, 50, 40, 30, 20, \
      \           19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2
      number$() = "billion", "million", "thousand", "hundred", "ninety", "eighty", \
      \           "seventy", "sixty", "fifty", "forty", "thirty", "twenty", \
      \           "nineteen", "eighteen", "seventeen", "sixteen", "fifteen", \
      \           "fourteen", "thirteen", "twelve", "eleven", "ten", "nine", \
      \           "eight", "seven", "six", "five", "four", "three", "two"
 
      IF n% < 0 THEN = "minus " + FNsaynumber(-n%)
      IF n% = 0 THEN = "zero"
      IF n% = 1 THEN = "one "
 
      FOR i% = 0 TO DIM(number%(),1)
        IF n% >= number%(i%) THEN
          t% = n% DIV number%(i%)
          IF t%=1 AND i%<4 a$ += "one " ELSE IF t%<>1 a$ += FNsaynumber(t%)
          a$ += number$(i%)
          t% = n% MOD number%(i%)
          CASE TRUE OF
            WHEN i%>3 AND i%<12 AND t%<>0: a$ += "-"
            WHEN i%<=3 AND t%>=100: a$ += ", "
            WHEN i%<=3 AND t%<>0 AND t%<100: a$ += " and "
            OTHERWISE: a$ += " "
          ENDCASE
          IF t% a$ += FNsaynumber(t%) ELSE IF i%<12 a$ += " "
          EXIT FOR
        ENDIF
      NEXT i%
      = a$