将小数点后的值转换为较小的精度
可能的重复:
为什么十进制数不能用二进制精确表示?
我有一个问题,正在解决一个单纯形问题,经过几次迭代,在 1 次迭代中,该值变成了 0.400000,现在我将该值乘以 100 以获得40.000000。现在用 40 减去这个值,但结果是 0.000001。请帮我解决这个问题,我无法弄清楚这个值是如何变成 0.000001 的? 由于这个 .000001 在检查值时出现问题,即我正在与 0 进行比较,但编译器将此视为大于 0 的值,并且得到错误的答案。我该如何纠正此错误?
Possible Duplicate:
Why can't decimal numbers be represented exactly in binary?
I have a problem,am solving a simplex problem,while several iterations,in 1 iteration the value turned out to be .400000,now i am multiplying this value with 100 to obtain 40.000000.Now am subtracting this value with 40,but the solution is coming out to be .000001.Please help me out with this,am not able to figure out how this value is turning out to .000001??
As this .000001 is giving problems while checking value,i.e i am comparing with 0,but compiler is treating this as value greater than 0,and am getting wrong answer.How can i correct this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它与浮点数的机器精度有关。在这里阅读相关内容:http://en.wikipedia.org/wiki/Floating_point#Machine_ precision< /a>
It has to do with the machine precision in Floating points. Have a read about it here: http://en.wikipedia.org/wiki/Floating_point#Machine_precision