github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/humannumbers/ordinal.go (about) 1 package humannumbers 2 3 import "strconv" 4 5 // Ordinal returns the number + ordinal suffix 6 func Ordinal(i int) string { 7 s := strconv.Itoa(i) 8 9 switch i % 100 { 10 case 11, -11, 12, -12: 11 return s + "th" 12 } 13 14 switch i % 10 { 15 case 1, -1: 16 return s + "st" 17 case 2, -2: 18 return s + "nd" 19 case 3, -3: 20 return s + "rd" 21 default: 22 return s + "th" 23 } 24 }