MySQL float double type

Source: Internet
Author: User
Tags float double

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

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.