I am trying to compare 2 values in PHP.
My logic is:
- I have a remaining amount (a)
- I have a amount to be charged (b)
- I calculate remaining to be by ( a - b )
- After charge action I get the actual remaining value (c)
- I compare the value I got in #3 with (c)
Even though the both are similar PHP says they are not equal.
Below given is my code (with filled values)
<?php
$remaining_amount_before_payment = "600";
$remaining_amount_after_payment = (float)$remaining_amount_before_payment - (float)"387.60";
$actual_remaining_amount_after_payment = "212.4";
echo "actual_remaining_amount_after_payment: {$actual_remaining_amount_after_payment} <br><br>";
echo "remaining_amount_after_payment: {$remaining_amount_after_payment} <br><br>";
var_dump( ((float)$actual_remaining_amount_after_payment) == ((float)$remaining_amount_after_payment) );?>
I type cast the values to float
, but the var_dump
returns FALSE
.
Can anybody help me to find out why this is?
I am using PHP 5.6.
Thanks in advance!