2023-06-02 11:24:58 +00:00
|
|
|
package format
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2023-09-21 10:34:29 +00:00
|
|
|
// 厘转美元(四舍五入)
|
2023-09-21 10:21:31 +00:00
|
|
|
func CentitoDollar(price int64, remainFloatPoint ...uint) string {
|
|
|
|
s := "%0.3f"
|
2023-09-21 03:14:14 +00:00
|
|
|
if len(remainFloatPoint) > 0 {
|
2023-09-21 10:21:31 +00:00
|
|
|
s = fmt.Sprintf("%%0.%df", remainFloatPoint[0])
|
2023-09-21 03:14:14 +00:00
|
|
|
}
|
2023-09-21 10:21:31 +00:00
|
|
|
return fmt.Sprintf(s, float64(price)/float64(1000))
|
2023-06-02 11:24:58 +00:00
|
|
|
}
|
2023-09-21 04:11:15 +00:00
|
|
|
|
2023-09-21 10:34:29 +00:00
|
|
|
// 厘转美元(向下截断,舍弃掉厘)用于计算总价
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2023-09-21 04:11:15 +00:00
|
|
|
// 厘转美元
|
2023-09-21 06:26:14 +00:00
|
|
|
func CentitoDollarStr(price float64) string {
|
2023-09-21 10:22:55 +00:00
|
|
|
s := "%0.2f"
|
2023-09-21 06:26:14 +00:00
|
|
|
return fmt.Sprintf(s, price/float64(1000))
|
2023-09-21 04:11:15 +00:00
|
|
|
}
|