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.


10 INPUT "GIMME A NUMBER! "; N
20 GOSUB 100"NUMBER NAME
30 PRINT R$
40 END
 
100 REMNUMBER NAME
110 IF R$ = "" THEN FOR I = 0 TO 10 : READ S$(I), T$(I), U$(I), V$(I) : NEXT
120 IF N = 0 THEN R$ = "ZERO" : RETURN
130 R$ = "" : D = 10 : C = 100 : M = 1E3
140 A = ABS(N)
150 FOR U = 0 TO D
160     H = A - C * INT(A / C)
170     IF H > 0 AND H < D THEN R$ = S$(H) + " " + R$
180     IF H > 9 AND H < 20 THEN R$ = T$(H - D) + " " + R$
190     IF H > 19 AND H < C THEN S = H - D * INT(H / D) : R$ = U$(INT(H / D)) + MID$("-",1+(S=0),1) + S$(S) +  " " + R$
200     H = A - M * INT(A / M)
210     H = INT (H / C)
220     IF H THEN R$ = S$(H) + " HUNDRED " + R$
230     A = INT(A / M)
240     IF A > 0 THEN H = A - M * INT(A / M) : IF H THEN R$ = V$(U) + " " + R$
250     IF A > 0 THEN NEXT U
260 IF N < 0 THEN R$ = "NEGATIVE " + R$
270 RETURN
 
280 DATA "", "TEN", "", "THOUSAND"
281 DATA "ONE", "ELEVEN", "", "MILLION"
282 DATA "TWO", "TWELVE", "TWENTY", "BILLION"
283 DATA "THREE", "THIRTEEN", "THIRTY", "TRILLION"
284 DATA "FOUR", "FOURTEEN", "FORTY", "QUADRILLION"
285 DATA "FIVE", "FIFTEEN", "FIFTY", "QUINTILLION"
286 DATA "SIX", "SIXTEEN", "SIXTY", "SEXTILLION"
287 DATA "SEVEN", "SEVENTEEN", "SEVENTY", "SEPTILLION"
288 DATA "EIGHT", "EIGHTEEN", "EIGHTY", "OCTILLION"
289 DATA "NINE", "NINETEEN", "NINETY", "NONILLION"
290 DATA "", "", "", "DECILLION"