Reputation: 13
I have been working on a project with a lot of numbers inserted in a database table. Now that I finished the code, I was checking the values for errors and I noticed my value 3075277 would transform in 3075280 when inserted in the db and 3075255 would be 3075260.
The colummn type is Float. What should I change to disable the rounding? This one doesn't even have decimals numbers, why would it round like that? I use the default options, only changed collation to utf8_general_ci and change the type to varchar and lenght in some and float in others.
Upvotes: 1
Views: 2759
Reputation: 142298
This issue is with MySQL, not Phpmyadmin.
FLOAT
has 6-7 significant digits of precision, as you are seeing with the mangled values. By "significant digits", I mean starting anywhere:
1234567xxxx.
12345.67xxx
1.234567xxx
0.0000001234567xxx
That is the xxx
is likely to be zeros or some kind of 'noise', not the original value you put into the column.
DOUBLE
gives you about 16 significant digits.
DECIMAL(9,0)
gives you 9 digits to the left of the decimal point, none afterwards. Sort of like INT
.
DECIMAL(9,4)
gives you 5 (9-4) digits to the left of the point; 4 afterwards.
What kinds of numbers are you storing? Money? Scientific measurements? Astronomical distances? DT's wealth?
Upvotes: 1
Reputation: 6305
Now you are using FLOAT
type but getting error because you are saving big decimal number in the database. You should go for DOUBLE
.
Although FLOAT
and DOUBLE
are similar because they store the value in approximate value, but that DOUBLE is 8-bytes, and FLOAT
is 4-bytes.
A FLOAT is for single-precision, while a DOUBLE is for double-precision numbers.
MySQL uses four bytes for single-precision values and eight bytes for double-precision values.
There is a big difference from floating point numbers and decimal (numeric) numbers, which you can use with the DECIMAL data type. This is used to store exact numeric data values, unlike floating point numbers, where it is important to preserve exact precision, for example with monetary data.
So as in your case, for larger numbers you would want DOUBLE
instead of FLOAT
.
Upvotes: 0