MySQL float Double Type

Source: Internet
Author: User
Tags float double

Generally, the number type in Oracle is set to number without length, which provides better scalability.

You don't need to worry about integer or decimal number, and the space occupied by length is also related to the stored value.

The length of the Value Type in MySQL is relatively fixed, and there is no foundation for the use of float. Direct use

Perform a small test on the value.

######################################## ##########################

Mysql> show create table tmp_xf_test \ G **************************** 1. row *************************** table: tmp_xf_testcreate table: create Table 'tmp _ xf_test '('t1' float () default null, 't2' float default null, 't3' Double () default null, 't4 'Double default null) engine = MyISAM default charset = gbk1. mysql> insert into tmp_xf_test values (5.1, 5.1, 5.1, 5.1 ); | 5.1000 | 5.1 | 5.1000 | 5.1 | -- set the specific precision, followed by 0 to complete 2. 123456789.123456789 | 999.9999 | 1.23457e + 08 | 999.9999 | 123456789.123457 | -- limit () overflow 3. 123.4567 | 123.4567 | 123.457 | 123.4567 | 123.4567 | 4. 123.45678 | 123.4568 | 123.457 | 123.4568 | 123.45678 | 5. 1234.456 | 999.9999 | 1234.46 | 999.9999 | 1234.456 | -- overflow 6. 0.00009 | 0.0001 | 9e-05 | 0.0001 | 9e-05 | 7. 0.123456789012345678901 | 0.1235 | 0.123457 | 0.1235 | 0.123456789012346 | -- 16-bit valid length 8. 12345678901234567890.123456789012345678901 | 999.9999 | 1.23457e + 19 | 999.9999 | 1.23456789012316e + 19 | -- float 7-bit valid length; Double 16-bit valid length 9. 12345678901234567890 | 999.9999 | 1.23457e + 19 | 999.9999 | 1.23456789012316e + 19 |

----------------------- Reference Manual

Http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html

The float and double data types are used to represent approximate numeric

Data values.

For float, the SQL standard allows an Optional specification of the Precision

(But not the range of the exponent) in BITs following the keyword float in parentheses.

MySQL also supports this optional precision specification, but the precision value is

Used only to determine storage size. A precision from 0 to 23 results in a four-byte

Single-precisionfloat column. A precision from 24 to 53 results in an eight-byte

Double-precision double column.

MySQL allows a nonstandard Syntax: Float (M, d) or real (M, d) or double

Precision (M, d). Here, "(m, d)" means than values can be stored with up to M digits

In total, of which D digits may be after the decimal point. For example, a column defined

As float (999.9999) will look like-when displayed. MySQL performs rounding when

Storing values, so if you insert 999.00009 into a float () column, the approximate

Result is 999.0001.

-- Floating point number can refer to the http://www.ibm.com/developerworks/cn/java/j-math2.html

mysql> select * from tmp_xf_test;+----------+-------------+----------+----------------------+| t1       | t2          | t3       | t4                   |+----------+-------------+----------+----------------------+|   5.1000 |         5.1 |   5.1000 |                  5.1 || 999.9999 | 1.23457e+08 | 999.9999 |     123456789.123457 || 123.4567 |     123.457 | 123.4567 |             123.4567 || 123.4568 |     123.457 | 123.4568 |            123.45678 || 999.9999 |     1234.46 | 999.9999 |             1234.456 ||   0.0001 |       9e-05 |   0.0001 |                9e-05 ||   0.1235 |    0.123457 |   0.1235 |    0.123456789012346 || 999.9999 | 1.23457e+19 | 999.9999 | 1.23456789012346e+19 || 999.9999 | 1.23457e+19 | 999.9999 | 1.23456789012346e+19 |+----------+-------------+----------+----------------------+9 rows in set (0.00 sec)

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.