Take this code for example:
print 2.0 == 2 #---> returns True
print 12 % 5 #---> returns 2
print ((12.0 / 5) - (12 / 5)) * 5 #---> returns 2.0
print ((12.0 / 5) - (12 / 5)) * 5 == 12 % 5 #---> returns False (What the hell happens here?)
Because the first calculation does not return exactly 2.0:
>>> ((12.0 / 5) - (12 / 5)) * 5
1.9999999999999996
print limits floating point display to 12 significant digits only, causing the value to be rounded to 2.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With