1.float type
The default length of the float column type does not find the result. Precision must be specified.
For example , num float, INSERT into table (num) values (0.12); Select * FROM table where num=0.12 words. Empty set.
Num Float (9,7), insert into table (num) values (0.12); Select * FROM table where num=0.12 will find this record.
Mysql> CREATE TABLE TT
(
Num Float (9,3)
);
Query OK, 0 rows affected (0.03 sec)
Mysql> INSERT INTO TT (NUM) values (1234567.8);
ERROR 1264 (22003): Out of Range value to column ' num ' at row 1
Note: Out of field range, unable to insert
Mysql> INSERT INTO TT (NUM) values (123456.8);
Query OK, 1 row Affected (0.00 sec)
Mysql> Select* from tt;
+------------+
| num |
+------------+
| 123456.797 |
+------------+
1 row in Set (0.00 sec)
Note: The number of decimal place is not enough, the initiative to fill, but there is a problem is as above the approximate value.
Mysql> INSERT INTO TT (NUM) values (123456.867);
Query OK, 1 row affected (0.04 sec)
Mysql> SELECT *from TT;
+------------+
| num |
+------------+
| 123456.797 |
| 123456.797 |
| 123456.867 |
+------------+
3 Rows in Set (0.00 sec)
Mysql> Select* from TT where num=123456.867;
+------------+
| num |
+------------+
| 123456.867 |
+------------+
1 row in Set (0.00 sec)
Mysql> INSERT INTO TT (NUM) values (2.8);
Query OK, 1 row affected (0.04 sec)
Mysql> SELECT *from TT;
+------------+
| num |
+------------+
| 123456.797 |
| 123456.797 |
| 123456.867 |
| 2.800 |
+------------+
4 rows in Set (0.00 sec)
Mysql> Select* from TT where num=2.8;
+-------+
| Num |
+-------+
| 2.800 |
+-------+
1 row in Set (0.00 sec)
Mysql> INSERT INTO TT (NUM) values (2.888888);
Query OK, 1 row Affected (0.00 sec)
Mysql> Select* from tt;
+------------+
| num |
+------------+
| 123456.797 |
| 123456.797 |
| 123456.867 |
| 2.800 |
| 2.889 |
+------------+
5 rows in Set (0.00 sec)
Note: The number of decimal place is super, and take the approximate value on their own initiative.
--------------------------------------------------------------------------------------
2.double type
Mysql> CREATE TABLE TT (
Num double (9,3)
);
Query OK, 0 rows affected (0.02 sec)
Mysql> INSERT INTO TT (NUM) values (234563.9);
Query OK, 1 row Affected (0.00 sec)
Mysql> SELECT * fromtt;
+------------+
| num |
+------------+
| 234563.900 |
+------------+
1 row in Set (0.00 sec)
Mysql> INSERT INTO TT (NUM) values (2345623.2);
ERROR 1264 (22003): Out of Range value to column ' num ' at row 1
Mysql> INSERT INTO TT (NUM) values (234563.2);
Query OK, 1 row Affected (0.00 sec)
Mysql> Select* from tt;
+------------+
| num |
+------------+
| 234563.900 |
| 234563.200 |
+------------+
2 rows in Set (0.00 sec)
Mysql> INSERT INTO TT (NUM) values (2.8);
Query OK, 1 row Affected (0.00 sec)
Mysql> Select* from TT;
+------------+
| num |
+------------+
| 234563.900 |
| 234563.200 |
| 2.800 |
+------------+
3 Rows in Set (0.00 sec)
FLOAT (M,D) or real (m,d) or double PRECISION (m,d). Here, "(M,d)" indicates that the value displays a total of M-bit integers. The D-bit is located after the decimal point.
For example, a column defined as float (7,4) can be displayed as-999.9999.
MySQL is rounded when the value is saved, so assume that 999.00009 is inserted in float (7,4) aligns, and the approximate result is 999.0001.
MySQL float double type