python 计算浮点数的精度问题

测试代码如下:
x, y = 0.1, 0.2
z = x + y
print(x, y)  # 0.1 0.2
print(z)  # 0.30000000000000004
print(z == 0.3)  # False

总结:我想各种编程语言都存在这个问题,编程时需要注意。

猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/85234414