fusenapi/utils/format/price.go
2023-09-21 14:26:14 +08:00

25 lines
477 B
Go

package format
import (
"fmt"
"strconv"
)
// 厘转美元
func CentitoDollar(price int64, remainFloatPoint ...uint) float64 {
s := "%.3f"
if len(remainFloatPoint) > 0 {
s = fmt.Sprintf("%%.%df", remainFloatPoint[0])
}
fmt.Println(s)
str := fmt.Sprintf(s, float64(price)/float64(1000))
dollar, _ := strconv.ParseFloat(str, 64)
return dollar
}
// 厘转美元
func CentitoDollarStr(price float64) string {
s := "%.2f"
return fmt.Sprintf(s, price/float64(1000))
}