MySQL float double type

Source: Internet
Author: User
Tags float double

1.float type
Float column Type default length cannot find results, you must specify precision,
For example , num float, INSERT into table (num) values (0.12); Select * from table where num=0.12, 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 digits is not enough, auto-fill, but there is a problem is the approximate value above.

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 digits is super, the approximate value is automatically taken.

--------------------------------------------------------------------------------------

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, where the D-bit is behind 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 if you insert 999.00009 in float (7,4) aligns, the approximate result is 999.0001.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.