3
I’m having a problem comparing two numbers, follow my code:
// Valor
$total_ch = 691.11;
// Calcula valor total das contas a receber
$result = $mysqli->query("SELECT SUM(valor) FROM contas_receber where status = '1' and id IN ($contas)");
$row = mysqli_fetch_array($result);
$valor_contas = $row['SUM(valor)'];
// Verifica se o total dos cheques e maior que os das contas a receber
if ($valor_contas > $total_ch) {
// Exibe Alert
echo "erro";
}
The value returned from $row['SUM(valor)']
is 691.11. Therefore, the two values are equal, but the system is pointing out which value of valor_contas
is greater than that of total_ch
.
What is causing this? How to solve?
It may be that he is rounding up the value of
$valor_contas
. Send the BD structure. Another thing is that it will take the total value of everything that came from select, so we need to know which value it returns.– Mauro Alexandre
Got it. Well the value field is so
valor decimal(10,2) DEFAULT NULL
. I sent an echo in the two variables, and the value written on the screen are the same. what I’m not getting.– Hugo Borges
But get in the if?
– Miguel
yes come in, and write
echo "erro";
– Hugo Borges
Gives a
var_dump()
in both variables.– rray
On the php website explain something about comparing float numbers http://php.net/manual/en/language.types.float.php
– Augusto