Mysqlfloatdouble type bitsCN.com
1. float type
The float column type cannot be found by default. the precision must be specified,
For example, if num float, insert into table (num) values (0.12); select * from table where num = 0.12, empty set.
Num float (0.12), insert into table (num) values (0.12); select * from table where num = 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 for column 'num' at row 1
Note: The field is out of the range and cannot be inserted.
Mysql> insert into tt (num) values (123456.8 );
Query OK, 1 row affected (0.00 sec)
Mysql> select * from tt;
+ ------------ +
| Num |
+ ------------ +
| 1, 123456.797 |
+ ------------ +
1 row in set (0.00 sec)
Note: If the number of decimal places is not enough, it is automatically filled. However, there is a problem that the approximate values above exist.
Mysql> insert into tt (num) values (123456.867 );
Query OK, 1 row affected (0.04 sec)
Mysql> select * fromtt;
+ ------------ +
| Num |
+ ------------ +
| 1, 123456.797 |
| 1, 123456.797 |
| 1, 123456.867 |
+ ------------ +
3 rows in set (0.00 sec)
Mysql & gt; select * from tt where num = 123456.867;
+ ------------ +
| Num |
+ ------------ +
| 1, 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 * fromtt;
+ ------------ +
| Num |
+ ------------ +
| 1, 123456.797 |
| 1, 123456.797 |
| 1, 123456.867 |
| 1, 2.800 |
+ ------------ +
4 rows in set (0.00 sec)
Mysql & gt; select * from tt where num = 2.8;
+ ------- +
| Num |
+ ------- +
| 1, 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 |
+ ------------ +
| 1, 123456.797 |
| 1, 123456.797 |
| 1, 123456.867 |
| 1, 2.800 |
| 1, 2.889 |
+ ------------ +
5 rows in set (0.00 sec)
Note: If the number of decimal places exceeds the upper limit, the approximate value is automatically obtained.
Bytes --------------------------------------------------------------------------------------
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 |
+ ------------ +
| 1, 234563.900 |
+ ------------ +
1 row in set (0.00 sec)
Mysql> insert into tt (num) values (2345623.2 );
ERROR 1264 (22003): Out of range value for 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 |
+ ------------ +
| 1, 234563.900 |
| 1, 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 |
+ ------------ +
| 1, 234563.900 |
| 1, 234563.200 |
| 1, 2.800 |
+ ------------ +
3 rows in set (0.00 sec)
FLOAT (M, D), REAL (M, D), or double precision (M, D ). Here, "(M, D)" indicates that the value displays a total of M-bit integers, where D is behind the decimal point.
For example, a column defined as FLOAT (999.9999) can be displayed. MySQL returns a rounded value when saving the value. Therefore, if 999.00009 is inserted in the FLOAT (999.0001) column, the approximate result is.
BitsCN.com