开发者

how to compute division accurately in python?

开发者 https://www.devze.com 2022-12-07 17:30 出处:网络
I tried the following computation in python: >>> 12.2 / 0.2 60.99999999999999 it\'s obviously that i开发者_如何学JAVAt didn\'t return the exact answer.

I tried the following computation in python:

>>> 12.2 / 0.2
60.99999999999999

it's obviously that i开发者_如何学JAVAt didn't return the exact answer.

According to the answers in text, l have known that we can use decimal.Decimal to obtain accurate calculation。 But I'm confused that if I have to use decimal.Decimal every time in my project to obtain exact results, is there any other method to ensure obtaining exact results in practice?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号