1
I have a very strange problem here.
It is a code for cash closing, I have the total value of sales, the user informs sales in credit, debit and cash, if the sum of the 3 is equal to the total sales he lets close the box.
The problem is that pro PHP 211.1 - 211.1 = -2.8421709430404E-14
public function isValid($value, $context = null)
{
foreach ($context as $key => $valor) {
$valor = str_replace('.', '', $valor);
$valor = str_replace(',', '.', $valor);
$context[$key] = (float)number_format($valor, 2);
}
$total = $context['total_pedidos'] - ($context['valor_credito'] + $context['valor_debito'] + $context['valor_dinheiro']);
var_dump($context);
var_dump($total);
die();
$this->setValue($total);
if(empty($total)){
return true;
}else{
$this->error(self::FLOAT);
return false;
}
}
Another thing, how I used the number_format($valor, 2)
it should put 2 decimal places no?
When I play other values it makes the correct account.
I am using PHP 5.5.12
Read as well Best kind of data to work with money?
– Woss
And also What is the correct way to use the float, double and decimal types?
– Woss