It doesn’t seem to display certain numbers correctly. It says “twentyth” rather than “twentieth”, “twenty oneth” rather than “twenty first” and “one hundred” rather than “one hundredth”.
This is the code I use.
[spoiler][code][ OrdinalNumber n f;
if (n == 0) { print “zeroth”; rfalse; }
if (n < 0) { print "minus "; n = -n; } #Iftrue (WORDSIZE == 4);
if (n >= 1000000000) {
if (f == 1) print ", “;
print (LanguageNumber) n/1000000000, " billion”; n = n%1000000000; f = 1;
}
if (n >= 1000000) {
if (f == 1) print ", “;
print (LanguageNumber) n/1000000, " million”; n = n%1000000; f = 1;
} #Endif;
if (n >= 1000) {
if (f == 1) print ", “;
print (LanguageNumber) n/1000, " thousand”; n = n%1000; f = 1;
}
if (n >= 100) {
if (f == 1) print ", “;
print (LanguageNumber) n/100, " hundred”; n = n%100; f = 1;
}
if (n == 0) {
print “th”;
rfalse;
}
if (f == 1) print " and ";
switch (n) {
1: print “first”;
2: print “second”;
3: print “third”;
4: print “fourth”;
5: print “fifth”;
6: print “sixth”;
7: print “seventh”;
8: print “eighth”;
9: print “ninth”;
10: print “tenth”;
11: print “eleventh”;
12: print “twelveth”;
13: print “thirteenth”;
14: print “fourteenth”;
15: print “fifteenth”;
16: print “sixteenth”;
17: print “seventeenth”;
18: print “eighteenth”;
19: print “nineteenth”;
20 to 99: switch (n/10) {
2: print “twent”;
3: print “thirt”;
4: print “fort”;
5: print “fift”;
6: print “sixt”;
7: print “sevent”;
8: print “eight”;
9: print “ninet”;
}
if (n%10 ~= 0) {
print "y ", (OrdinalNumber) n%10;
}
else {
print “ieth”;
}
}
];
-).
To say (something - number) in ordinal words: (- print (OrdinalNumber) {something}; -).[/code][/spoiler]
Thanks, climbingstars. I did refactor after Erik’s post made it possible, but I decided to make it an I7 routine instead. That actually turned out to be easier and kept things purely I7. It also let me manipulate the result as indexed text, which I’m not sure is as easy with I6 print statements, although I may be wrong on that score.