I have a field in a MySQL table called quantity.
I would like the quantity field to be able to store the following numbers: 0.25, 0.5, 0.75 and 1.
I currently have the field set as DECIMAL(2,2) as according to the MySQL docs.
It all works well, except for the 1, it always stores in the field as 0.99. Is there a way I can make this store as 1 instead of 0.99?
I have also tried passing in 1.0 and 1.00, but this also stores as 0.99.
CodePudding user response:
DECIMAL(2,2)
defines a two-digit number with two decimal places. It will only store two decimal digits. 0.99 is the closest it can get to 1.0
Use DECIMAL(3,2)
- that's a three-digit number with two decimal places. That will allow space for the integer portion.