-1

hello I have a problem wtich two variables in php. i have this code:

     var_dump($total);echo '<br/>';
     var_dump($reserva->getAdelanto());
     if ($total == $reserva->getAdelanto()){
        $total = 0;
        echo "hello";
        }
    else
        $total = $total - $reserva->getAdelanto();

print :

float(3940.2) 
float(3940.2)

but does not enter the if when the two variables are equal. anyone knows why is that? greetings and thanks.

faisbu
  • 275
  • 1
  • 3
  • 18
  • I've faced this problem in C++ too. To solve this what I do is to check their difference. for an example if(abs($x-$y) – Fallen Jun 25 '13 at 12:00

1 Answers1

1

May be try with abs like

if ((abs($a)-abs($b)) <= 0.00001) {
   echo "same";
}

Or

if (abs($a - $b) <= 0.00001) {
   echo "same";
}

Or you also try like

var_dump( bccomp($a, $b) == 0 )

returns true if they are same

Gautam3164
  • 28,027
  • 10
  • 58
  • 83