This is a pretty easy question.
I am doing a division of 1.2/0.2 on python 3.7.0 and I get 5.9999999999 instead of a clear 6. It is obvious that 1.2/0.2 is 6 so I don't understand why I am getting this result.
Thanks
This is a pretty easy question.
I am doing a division of 1.2/0.2 on python 3.7.0 and I get 5.9999999999 instead of a clear 6. It is obvious that 1.2/0.2 is 6 so I don't understand why I am getting this result.
Thanks
you can round a number, for example
round(1.2 / 0.2)
would give an answer of 6. The reason your getting this is due to floating point precision error.
It's a problem caused when the internal representation of floating-point numbers, which uses a fixed number of binary digits to represent a decimal number. It is difficult to represent some decimal number in binary, so in many cases, it leads to small roundoff errors.
you can read more here