0
$a->b = 7.56704843521;
$a->c = 7.56704843521;

But

$a->b == $a->c

returns false.

How can that be?

Even when doing floatval($a->b) == floatval($a->c) is false, and it should not be necessary anyway when using type-independent comparison "==" instead of "===".

Full code is

$a->b = 7.56704843521;
$a->c = 7.06704843521+0.5;

Thanks!

Raphael Jeger
  • 5,024
  • 13
  • 48
  • 79
  • 1
    Works fine for me! Please show us your full code! See: http://3v4l.org/EHS23 – Rizier123 Mar 16 '15 at 19:21
  • Read the [PHP docs](http://www.php.net/manual/en/language.types.float.php#language.types.float.comparison) for details on why you shouldn't use `==` to compare floats, and how you should compare floats: `$epsilon = 0.0000001; if(abs($a->b-$a->c) < $epsilon) { echo "true"; } ` [demo](http://ideone.com/oeejDZ) – Mark Baker Mar 16 '15 at 19:22
  • `echo sprintf("%.20lf", 7.06704843521+0.5);` <- And then you compare the numbers with your eyes – Rizier123 Mar 16 '15 at 19:24
  • so for my usecase (comparing geo-latitude) it's ok to compare intval() as it seems? – Raphael Jeger Mar 16 '15 at 19:29

0 Answers0