To add right ordinal indicator: st/nd/rd/th
suffix you can make use of switch case
.I have created a sample program to print all days of month along with their respective suffixes as follows:
package main
import (
"fmt"
)
func getDaySuffix(n int) string {
if n >= 11 && n <= 13 {
return "th"
} else {
switch n % 10 {
case 1:
return "st"
case 2:
return "nd"
case 3:
return "rd"
default:
return "th"
}
}
}
func main() {
for i := 1; i < 32; i++ {
suf := getDaySuffix(i)
fmt.Println(i, suf)
}
}
Output:
1 st
2 nd
3 rd
4 th
5 th
6 th
7 th
8 th
9 th
10 th
11 th
12 th
13 th
14 th
15 th
16 th
17 th
18 th
19 th
20 th
21 st
22 nd
23 rd
24 th
25 th
26 th
27 th
28 th
29 th
30 th
31 st