In my PHP code I have a variable that corresponds to the sum and difference of some values obtained from a MySQL database. This is the code:
<?php echo $verifica = (($valoreEntrate + $valoreInCassa) - ($valoreUscite + $valorePagamentiInSospeso + $valoreDaLasciareInCassa + $valoreDaPortareACasa)); ?>
Here is values of all variables involved obtained with echo:
$valoreEntrate = 3837.67
$valoreInCassa = 612.10
$valoreUscite = 97.81
$valorePagamentiInSospeso = 0
$valoreDaLasciareInCassa = 617.80
$valoreDaPortareACasa = 3734.22
The value of $verifica is:
$verifica = -0.0599999999995
Instead of -0.6 like I expected…
Can anyone explain why this value?
Thank you so much!!!
Bye…
This is because they are
floattypes, and floats are not stored as exact numbers. See PHP’s entry on float for further information.