Mysql float double Type

Source: Internet
Author: User
Tags float double

1. float Type
The float column type cannot be found by default. The precision must be specified,
For example, numFloat,InsertTable (num) values (0.12); select* From table where num = 0.12, empty set.
Num float (9, 7 ),InsertTable (num) values (0.12); select* If from table where num = 0.12, this record is found.

Mysql> create table tt
-> (
-> NumFloat (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* FromTt;
+ ------------ +
| 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> select* From tt whereNum = 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 |
|2.800 |
+ ------------ +
4 rows in set (0.00 sec)

Mysql> select* From tt whereNum = 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* FromTt;
+ ------------ +
| Num|
+ ------------ +
| 1, 123456.797 |
| 1, 123456.797 |
| 1, 123456.867 |
|2.800 |
|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 (
-> NumDouble (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* FromTt;
+ ------------ +
| 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 |
|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.

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.