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.


var 
   ns   =[1..20].chain([30..90,10]).walk(),
   names=T("one","two","three","four","five","six","seven","eight","nine",
           "ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen",
           "seventeen","eighteen","nineteen","twenty",
	   "thirty","forty","fifty","sixty","seventy","eighty","ninety"),
   hs    =T(  100,     1000,      1000000, 1000000000,1000000000000),
   hnames=T("hundred","thousand","million","billion", "trillion");
 
fcn numberToString(n){ // n>0
   fcn(n){
      if(100<=n<0d100_000_0000_000){
	 idx,h,name,r := hs.filter1n('>(n))-1, hs[idx], hnames[idx], n%h;
	 String(self.fcn(n/h),name, 
	    if(r==0) "" else if(0<r<100) " and " else ", ", 
	    self.fcn(r));
      }else if(0<n<=90){
	 idx,t,name,r := ns.filter1n('>(n))-1, ns[idx], names[idx], n-t;
	 String(name, if(0<r<10) "-" else " ", self.fcn(r));
      }else ""
   }(n).strip()  // sometimes there is a trailing space
}