Well, it is usually hard to prove that something doesn't exist. But I have never come across any function in kotlin-stdlib
that would do this or could be immediately adapted for this. Moreover, kotlin-stdlib
doesn't seem to contain anything locale-specific (which number ordinals certainly are).
I guess you should actually resort to some third-party software or implement your own solution, which might be something as simple as this:
fun ordinalOf(i: Int) {
val iAbs = i.absoluteValue // if you want negative ordinals, or just use i
return "$i" + if (iAbs % 100 in 11..13) "th" else when (iAbs % 10) {
1 -> "st"
2 -> "nd"
3 -> "rd"
else -> "th"
}
}
Also, solutions in Java: (here)