Python modulo on floats

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 % … Read more

What’s the syntax for mod in java

Instead of the modulo operator, which has slightly different semantics, for non-negative integers, you can use the remainder operator %. For your exact example: if ((a % 2) == 0) { isEven = true; } else { isEven = false; } This can be simplified to a one-liner: isEven = (a % 2) == 0;