Decimal datatype is rounding the values
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
DECIMAL
column?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.215
is saved as10.22
and10.214
becomes10.21
).If it is
DECIMAL(10)
it will not have any decimal values and be rounded to an integer.If you use
FLOAT
orDOUBLE PRECISION
you don't have to specify the number of decimal values but it has its own flaws.
Scott
Updated on June 25, 2022Comments
-
Scott almost 2 years
I have set my
MySQL
field table data type to thedecimal
because from what I have read, I would be able to store the price with commas/dots in thedecimal
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?