I have set my MySQL field table data type to the decimal because from what I have read, I would be able to store the price with commas/dots in the decimal data type fields… The problem is that whenever I store any data with the comma or dot, MySQL is rounding it automatically up or down. Eg. When I’m executing the following query:
UPDATE table SET field = 114.21 WHERE id = 1;
Then field is set, but the value is rounded to 114, instead of displaying the data I set in the query (114.21) – is there any solution for that? Or I should just use other data type?
AFAIK the dot is the standard notation for decimal values. Using Commas may trigger SQL parse errors or may go unnoticed if the syntactical context allows for a comma to be there.
How did you define the precision of the
DECIMALcolumn?If it is
DECIMAL(10, 2)it will have a total of 10 numbers of which 2 are decimal values (with 2 decimal rounding meaning that10.215is saved as10.22and10.214becomes10.21).If it is
DECIMAL(10)it will not have any decimal values and be rounded to an integer.If you use
FLOATorDOUBLE PRECISIONyou don’t have to specify the number of decimal values but it has its own flaws.