Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default size of datatype float in mysql - phpmyadmin

I have many float columns, But in phpmyadmin I didn't provide the size of float but unlike varchar, it still saves the column enter image description here

  1. what is the default size of float?

  2. should I enter the size manually like Float(10,2) Or it does not make much performance difference ?

Thanks :)

like image 330
user9050678 Avatar asked Dec 10 '17 11:12

user9050678


1 Answers

As mysql manual on float says:

For maximum portability, code requiring storage of approximate numeric data values should use FLOAT or DOUBLE PRECISION with no specification of precision or number of digits.

No length is the default length value.

However, if you do specify length, then mysql will round the float to the number of decimals specified. See the documentation linked above for more details:

For example, a column defined as FLOAT(7,4) will look like -999.9999 when displayed. MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.

like image 164
Shadow Avatar answered Sep 23 '22 11:09

Shadow