Floating point comparisons or why prices need to be stored in cents
Posted by Stanislav Furman on September 5, 2013In PHP you should be careful working with floating point number comparisons because sometimes the result that you get can be unexpected and unpredictable even if it looks pretty obvious. Here is an example. Can you guess what will be the result?
<?php
$a = 0.7;
$b = 0.1;
$c = $a + $b;
if ($c == 0.8) {
echo '$c == 0.8';
} else {
echo '$c!=0.8';
}
Continue reading