1 Star 0 Fork 0

wpkg/humanize

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ordinals.go 371 Bytes
一键复制 编辑 原始数据 按行查看 历史
arvin 提交于 2023-01-07 06:37 +08:00 . sync at Sat 07 Jan 2023 06:37:03 AM CST
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wpkg/humanize.git
git@gitee.com:wpkg/humanize.git
wpkg
humanize
humanize
main

搜索帮助