小编Int*_*ral的帖子

为什么0.1 + 0.2在Google Go中获得0.3?

只要使用浮点数,0.1就不能在内存中精确表示,所以我们知道这个值通常是0.10000000000000004.

但是当使用go时加0.1和0.2.我得到0.3.

fmt.Println(0.1 + 0.2)
// Output : 0.3
Run Code Online (Sandbox Code Playgroud)

为什么0.3出来而不是0.30000000000000004?

precision go

6
推荐指数
1
解决办法
427
查看次数

标签 统计

go ×1

precision ×1