mysql float double 類型

來源:互聯網
上載者:User

        一般在oracle的數字類型都設定為number不帶長度,這個擴充性比較好。

不太需要去關心是整數還是小數,而且長度所佔的空間也是和儲存的數值相關。

mysql中數實值型別占的長度比較固定,對於float的使用心裡沒什麼底。 直接用

數值進行小測一下。

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

mysql> show create table tmp_xf_test\G*************************** 1. row ***************************Table: tmp_xf_testCreate Table: CREATE TABLE `tmp_xf_test` (`t1` float(7,4) DEFAULT NULL,`t2` float DEFAULT NULL,`t3` double(7,4) 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 | --設定了具體精度的,小數後面會用0補全2. 123456789.123456789| 999.9999 | 1.23457e+08 | 999.9999 |     123456789.123457 | --限制(7,4)的  溢出了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 |  --溢出6. 0.00009|   0.0001 |       9e-05 |   0.0001 |                9e-05 |7. 0.123456789012345678901|   0.1235 |    0.123457 |   0.1235 |    0.123456789012346 |  --16位有效長度8. 12345678901234567890.123456789012345678901| 999.9999 | 1.23457e+19 | 999.9999 | 1.23456789012346e+19 | -- float 7位有效長度,double 16位有效長度9. 12345678901234567890| 999.9999 | 1.23457e+19 | 999.9999 | 1.23456789012346e+19 |

-----------------------具體參考手冊

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(7,4) will look like -999.9999 when displayed. MySQL performs rounding when

storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate

result is 999.0001.

--關於浮點數可以參考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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.