+ 1
How come the answer to the code below is different from the actual math?
Code: print((456/10**2)*(10**2)) Using python the out put is equal (455.99999999999994) But using the actual math it should be exactly (456) Please guys can you explain why their is a difference
5 Answers
+ 2
Hi, No One ! Thereâs a lot to read about this on the web. Try for example to start with this link:
https://www.geeksforgeeks.org/floating-point-error-in-JUMP_LINK__&&__python__&&__JUMP_LINK/amp/
+ 2
Hi, againNo One !
print(int(456/10**2) * (10**2))
This is :
= int(4.56) * 100
= 4 * 100
= 400
+ 1
Thank you
But I also have another question which is when I tried to change it to integer like this:-
print(int(456/10**2)*(10**2))
It outputs only 400 but why not 456 or 455 after all they are also integer like 400
+ 1
Python performs calculations in binary system. Try dividing in binary and convert to decimal.
0
Thank you đ