I'm trying to store decimals taken from input in a Mysql decimal (10,2) row. But when I enter 37.50 in the input, Mysql only stores 37.00 It seems to disregard everything after the dot. How can I store decimals?
this the input
So far I tried float:
$payrate=floatval($_POST['payrate']);
解决方案
It's unclear what you are asking. (Was there a question? Or was all that just intended as a status report?)
In a numeric context ...
MySQL interprets a "dot" character in a numeric literal as a decimal point.
MySQL interprets a "comma" character as invalid. MySQL reads the value from left to right until it hits an invalid character, and takes whatever it has read as the value.
As a demonstration, consider
SELECT '123,456.78' + 0 --> 123
SELECT '4t2' + 0 --> 4
If we need to pass a numeric value into MySQL that contains commas, and we want MySQL to disregard the commas, then we can remove the commas
SELECT REPLACE('123,456.78',',','') + 0 --> 123456.78
If we want a comma treated as the decimal separator, we can replace it with a dot character
SELECT REPLACE('456,78',',','.') + 0 --> 456.78
Of course, we could also do that string manipulation and cleanup of the value in the client, before we pass the value to MySQL.
Not sure if any of that answers the question you asked. Was there a question?