2023-06-02 19:24:58 +08:00
|
|
|
package format
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2023-09-15 14:52:36 +08:00
|
|
|
// 厘转美元
|
2023-09-21 11:14:14 +08:00
|
|
|
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))
|
2023-06-02 19:24:58 +08:00
|
|
|
dollar, _ := strconv.ParseFloat(str, 64)
|
|
|
|
return dollar
|
|
|
|
}
|
2023-09-21 12:11:15 +08:00
|
|
|
|
|
|
|
// 厘转美元
|
2023-09-21 14:26:14 +08:00
|
|
|
func CentitoDollarStr(price float64) string {
|
2023-09-21 12:11:15 +08:00
|
|
|
s := "%.2f"
|
2023-09-21 14:26:14 +08:00
|
|
|
return fmt.Sprintf(s, price/float64(1000))
|
2023-09-21 12:11:15 +08:00
|
|
|
}
|