Платформа ЦРНП "Мирокод" для разработки проектов
https://git.mirocod.ru
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
371 B
25 lines
371 B
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 |
|
}
|
|
|