This commit is contained in:
laodaming
2023-09-21 18:34:29 +08:00
parent f767af9a7f
commit e8546d615b
3 changed files with 14 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import (
"fmt"
)
// 厘转美元
// 厘转美元(四舍五入)
func CentitoDollar(price int64, remainFloatPoint ...uint) string {
s := "%0.3f"
if len(remainFloatPoint) > 0 {
@@ -13,6 +13,16 @@ func CentitoDollar(price int64, remainFloatPoint ...uint) string {
return fmt.Sprintf(s, float64(price)/float64(1000))
}
// 厘转美元(向下截断,舍弃掉厘)用于计算总价
func CentitoDollarWithNoHalfAdjust(price int64, remainFloatPoint ...uint) string {
s := "%0.2f"
if len(remainFloatPoint) > 0 {
s = fmt.Sprintf("%%0.%df", remainFloatPoint[0])
}
t := price / 10
return fmt.Sprintf(s, float64(t)/float64(100))
}
// 厘转美元
func CentitoDollarStr(price float64) string {
s := "%0.2f"