Python modulo on floats
Can anyone explain how the modulo operator works in Python? I cannot understand why 3.5 % 0.1 = 0.1 . abarnert Actually, it's not true that 3.5 % 0.1 is 0.1 . You can test this very easily: >>> print(3.5 % 0.1) 0.1 >>> print(3.5 % 0.1 == 0.1) False In actuality, on most systems, 3.5 % 0.1 is 0.099999999999999811 . But, on some versions of Python, str(0.099999999999999811) is 0.1 : >>> 3.5 % 0.1 0.099999999999999811 >>> repr(3.5 % 0.1) '0.099999999999999811' >>> str(3.5 % 0.1) '0.1' Now, you're probably wondering why 3.5 % 0.1 is 0.099999999999999811 instead of 0.0 . That's because of the usual