echo 65.7 * 100 % 10 // 0 echo 65.6 * 100 % 10 // 9 <--- echo 6560 % 10 // 0 echo 65.5 * 100 % 10 // 0
Can someone please explain why?
EDIT:
for human or non-programmers, the result 9 is apprently wrong.
how can I prevent this "error" when programming?
Because
65.6in floating point is actually an approximation of65.6. It is actually marginally less than65.6, i.e.65.5999or similar.Assuming my wild guess at the actual value is correct, you have
6559.9, which is stripped to6599by the modulus operator, then divided by 10 for remainder 9.