FormatFloat

This commit is contained in:
jiangyong27 2025-03-12 23:12:44 +08:00
parent 6acbd2c3e2
commit 845a8a40e8
1 changed files with 7 additions and 0 deletions

View File

@ -20,6 +20,13 @@ func FormatMoney(number int64) string {
return strconv.FormatInt(int64(num1), 10)
}
func FormatFloat(f float64) string {
if int64(f*100)%100 == 0 {
return fmt.Sprintf("%d", int64(f))
}
return fmt.Sprintf("%.2f", f)
}
func FormatPercent(number float64) string {
if number*100 == float64(int(number*100)) {
return fmt.Sprintf("%d%%", int(number*100))