0

What is going on here:

12 % 4 = 0; // integers

(1.2 / 0.1) % 4 = 3; // floats (12) % 4 = 3!

$a = 1.2 / 0.1;
$b = ((int)$a) % 4;
$c = 12 % 4;

print_r([
  $a,
  $b,
  $c,
]);
Script47
  • 14,230
  • 4
  • 45
  • 66
luky
  • 2,263
  • 3
  • 22
  • 40
  • solution is where? – luky Jul 11 '18 at 12:06
  • in the linked duplicate. IEEE 754 floats (used by almost all programming languages) cannot represent all arbitrary precision floating point numbers. This is a tradeoff made for various technical reasons. You are not the first (and won't be the last) to be tripped up by this, canonical example is `0.1 + 0.2 !== 0.3` – Jared Smith Jul 11 '18 at 12:12

0 Answers0