I have the following lines of code to check the balance of the user.
$balance = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]); $balance = number_format($balance["cash"],2);
And the following code to check the total cost of purchasing the stocks
$total = number_format($share["price"] * $_POST["quantity"],2);
But when I compare these two variables via
if($total > $balance)
it does not work as I intended. For example, if a user with balance of $10,000 tries to purchase 100 stock with symbol 'FREE'(which costs 0.03 (2d.p)), the $total seems to be greater than the $balance, thus an error occurs. Furthermore, when the number of stocks is 10 it seems to work. I even tried to convert the $_POST["quantity"] to integer first and then calculate the total but it still gave out the same result.
Any help would be appreciated!! Cheers