相关疑难解决方法(0)

Golang将float64转换为int错误

在将float转换为int时,如何避免浮点错误.例如,下面的代码打印出来:0.5499999999999972当我想要打印时0.55.

package main

import "fmt"

func main() {
    x := 100.55
    fmt.Println(x - float64(int(x)))    
}

Output:
0.5499999999999972
Run Code Online (Sandbox Code Playgroud)

floating-point precision go

3
推荐指数
1
解决办法
1546
查看次数

标签 统计

floating-point ×1

go ×1

precision ×1