I have two float variables that are equal, I retrieve them by PHP and subtract them. the result equals (7.105427357601E-15) I tried to change to double or to decimal and none of that worked. This is what I use in PHP:
$giftcard_balance = $giftcard['balance'];
$total = $product['price'];
$total -= $giftcard_balance;
echo $total;
Here instead of showing 0, it's showing (7.105427357601E-15)
Anyone can help please?
When dealing with prices and account balances you will find that DECIMAL(6, 2) is much easier to deal with than FLOAT. If you experience the same problem when using DECIMAL datatype please post a specific example.
Using round() or similar is a very bad idea as it is simply masking the problem, not fixing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With