golang int 转float
方法一:
强转:
代码如下:
import "fmt"
func main() {
var money int
money = 1
fmt.Println(float64(money) / float64(100))
}
输出结果:0.01
方法二:
高精度转:
代码如下:
import (
"fmt"
"math/big"
"strconv"
)
func main() {
totalAmount := 1
numrator, _ := new(big.Float).SetPrec(uint(1024)).SetString(strconv.Itoa(totalAmount))
denominator := big.NewFloat(100)
denominator1 := numrator.Quo(numrator, denominator)
fmt.Println(denominator1)
}
输出结果:0.01