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?
<strong>this the input</strong>
<input class='form-control formBlock' name='payrate' value='' step="0.01" type='number' placeholder="Pay Rate..." required>
So far I tried float:
<strike>It's unclear what you are asking. (Was there a question? Or was all that just intended as a status report?)</strike>
In a numeric context ...
MySQL interprets a "dot" character in a numeric literal as a decimal point.
MySQL interprets a "comma" character as <em>invalid</em>. 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<hr />
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.
<strike>Not sure if any of that answers the question you asked. Was there a question?</strike>