I have the following scenario:
$amount = '1000000000.00000001';
//echo $amount;
$query = $mysqli->prepare("UPDATE `wallets` SET `dollars` = `dollars` + ? WHERE `userId` = ?");
$query->bind_param('si', $amount, $id);
$query->execute();
The column dollars in the table is DECIMAL(18,8).
Now the problem is that if I execute this query and the current value of dollars is 0, then the new value in the table will be 1000000000.00000000. As you can see, the .00000001 got lost in the ether and my question is why?
I am specifically preventing this from happening by binding the $amount as a String and not as an Integer, yet it still gets converted to float (i assume) somewhere and cut off.
If I do this instead:
$query = $mysqli->prepare("UPDATE `wallets` SET `dollars` = `dollars` + 1000000000.00000001 WHERE `userId` = ?");
$query->bind_param('i', $id);
$query->execute();
Then it works perfectly fine and the table will contain the expected value 1000000000.00000001
So why is the $amount treated as a number, even though I am treating it as a string to make sure PHP won't screw with it?
How can I fix it?