Problem
PHP converts strings (if possible) to numbers ( source ). Floating points have limited accuracy ( source ). Therefore, $a == $b due to rounding errors.
Correction
Use === or !== .
Try
<?php $a = "3.14159265358979326666666666"; $b = "3.14159265358979323846264338"; if ($a == $b) { echo "'$a' and '$b' are equal with ==.<br/>"; } else { echo "'$a' and '$b' are NOT equal with ==.<br/>"; } if ($a === $b) { echo "'$a' and '$b' are equal with ===.<br/>"; } else { echo "'$a' and '$b' are NOT equal with ===.<br/>"; } ?>
Results in
'3.14159265358979326666666666' and '3.14159265358979323846264338' are equal with ==. '3.14159265358979326666666666' and '3.14159265358979323846264338' are NOT equal with ===.
Note
If you want to do the math with high precision, you should take a look at BC Math .
source share