# Integer to ordinal number string (words only)

I am trying to create a function that does:

f[1]
(* "first" *)

f[27]
(* "twentyseventh" *)

f[50]
(* "fiftieth *)


There need not be a hyphen or space in "twentyseventh".

I searched "OrdinalNumber" (Interpreter type), IntegerName, and SpokenString, but none of these seem to generate actual ordinal numbers composed of words only.

• I wrote a python script to do this. Right now it converts pretty large numbers but I want it to theoretically go up to infinity. Here's a link to the script on github: github.com/stephen-wolfe/python-scripts/blob/master/… – user62600 Jan 26 at 17:27

IntegerName as of Version 10 should fit the bill:

IntegerName[ 1, "Ordinal" ]


first

IntegerName[#, "Ordinal" ]& /@ {27, 50}


{"twenty-seventh", "fiftieth"}

It even produces word-only answers for longer ordinal numbers:

IntegerName[ 10000027, "Ordinal" ]


"ten million twenty-seventh"

Building a custom converter function (word-only) to OP's demands

The OP wants to remove Whitespace and - from the ordinal string which can be done using StringReplace within a custom function:

f[ i_Integer ] := With[
{
ordinalStringRules = StringReplace[ Whitespace | "-" -> "" ]
}
,
IntegerName[ i, "Ordinal" ] // ordinalStringRules
]

f[ 10000027 ]


"tenmilliontwentyseventh"

• @JungHwan Does this answer your question? – gwr Jan 30 at 13:02
• For a different, maybe more general, take on this problem see my answer here. – gwr Jan 31 at 11:20