Search code examples
iosnsnumberformatter

Spell out ordinal numbers


There are few ways to generate short ordinal numbers like "1st", "2nd", etc, with NSNumberFormatter (from iOS 9) or 3rd parties like FormatterKit.

There is also a way to spell out cardinal numbers with NSNumberFormatter that gives one, two, three.

However, I need to get the unabbreviated spelling - first, second, third.

I know that iOS internally can do it, because if I pass "1st" to AVSpeechUtterance it pronounces it as "first". I was wondering if there is any API to get a string with spelling of ordinal numbers, preferably, for multiple languages?


Solution

  • I couldn't find an existing libraries for that, so I created my own.

    It uses ICU4C underneath from the system libraries. Before using, please check how the example project works:

    https://github.com/dimat/DMNumberSpellOutFormatter