Search code examples
phpmysqlsqlsqldatatypes

phpMyAdmin Float Disable Round Number


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.


Solution

  • 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.