github.com/binbinly/pkg@v0.0.11-0.20240321014439-f4fbf666eb0f/util/parse.go (about) 1 package util 2 3 import ( 4 "fmt" 5 "math" 6 "strconv" 7 "strings" 8 ) 9 10 // ParseAmount 金额分转元,保留两位小数输出 11 func ParseAmount(amount int) float64 { 12 f, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", float64(amount)/100), 64) 13 return f 14 } 15 16 // FormatAmount 格式化金额为分,入库保存 17 func FormatAmount(amount float64) int { 18 return int(math.Ceil(amount * 100)) 19 } 20 21 // FormatResUrl 格式化图片资源完整路劲 22 func FormatResUrl(dfs, url string) string { 23 return strings.Join([]string{dfs, url}, "/") 24 }