0

I am getting something weird happening...

I am setting $cls to 8 via a very simple calculation, but then the if statement says it is not 8, even though I can echo out the value and confirm it is. I must be losing my mind or something!

<?php
$cls = ((0.1 + 0.7) * 10);

echo 'Number is ' . $cls;
if ($cls == 8) {
  echo ', you are smart.';
} else {
  echo ', you are nuts!';
}

?>

This produces "Number is 8, you are nuts!". Can someone explain what's happening here?

  • 1
    You seem to be hitting an edge case of internal value vs displayed precision. Take a look at [this](https://3v4l.org/O0XW6). The default value for precision is 14 and the value you need to see the displayed result as not 8 seems to be 16+ – apokryfos Jul 13 '23 at 13:56

0 Answers0