5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-28 18:21:35 +00:00
matterbridge/vendor/github.com/dustin/go-humanize/ordinals.go

26 lines
371 B
Go
Raw Normal View History

2021-10-16 21:11:32 +00:00
package humanize
import "strconv"
// Ordinal gives you the input number in a rank/ordinal format.
//
// Ordinal(3) -> 3rd
func Ordinal(x int) string {
suffix := "th"
switch x % 10 {
case 1:
if x%100 != 11 {
suffix = "st"
}
case 2:
if x%100 != 12 {
suffix = "nd"
}
case 3:
if x%100 != 13 {
suffix = "rd"
}
}
return strconv.Itoa(x) + suffix
}