Can anybody help me explain the following? You can type the same numbers into Google and get the same results as I am getting in code….
1089.80 % 0.04 = 0
1089.84 % 0.04 = 0.04 - Surely this is wrong? 0.04 goes into 1089.84 with no remainder.
1089.88 % 0.04 = 0
1089.92 % 0.04 = 0
Similar behaviour appears for other numbers that should seemingly be correct.
Thanks in advance!
You’re looking at the rounded values. Internally the number is not 1089.84 but something like 1089.84000026.
If you want “correct” values, multiply both sides by 100, add 0.5, and (int) them, then take the integer mod, and convert the result back to float.