In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The following mainly brings you the practical application operation of MySQL data floating point type. I hope these contents can bring you practical use, which is also the main purpose of this article when I edit the practical application operation of MySQL data floating point type. All right, don't talk too much nonsense, let's just read the following.
1. Background
* the floating point types supported by MySQL include single precision type (float), double precision type (double), and high precision type (decimal). It is recommended to use high precision type (decimal) in digital currency types.
* MySQL floating-point and fixed-point types can be represented by the type name plus (MMagneD). M represents the total length of the value, D represents the length after the decimal point, and M and D are also known as precision and scaling. For example, float (7Power4) can be displayed as-999.9999 when saving MySQL values. If 999.00009 is inserted, the result is 999.0001. When FLOAT and DOUBLE do not specify precision, the default is displayed according to the actual precision, while when DECIMAL does not specify precision, the default integer is 10 and the decimal is 0.
two。 The range of storage and values required for integer types
Type occupies space accuracy FLOAT4 single precision to 7 decimal places after decimal point DOUBLE8 double precision to 15 decimal places DECIMAL variable length high precision to 65 decimal places
3. M / G * G (! = | =) (not necessarily equal to) M in floating point applications
M = 3.1415 G = 2.1542, unified to 6 decimal places
* single precision (float) application
* create float_test table
Mysql > CREATE TABLE float_test (- > m FLOAT (10Power6),-> g FLOAT (10L6)->) ENGINE=INNODB CHARSET=utf8mb4;Query OK, 0 rows affected (0.06 sec)
* insert m and g data
Mysql > INSERT INTO float_test SELECT 3.1415 2.1542 * Records: 1 Duplicates: 0 Warnings: 0mysql > select * from float_test +-+-+ | m | g | +-+-+ | 3.141500 | 2.154200 | +-+-+ 1 row in set (2.154200 sec)
* perform M / G * G operations
Mysql > SELECT m / g * g, m FROM float_test;+-+-+ | m / g * g | m | +-+-+ | 3.1414999962 | 3.141500 | +-+-+ 1 row in set (sec)
* double precision (double) application
* create double_test table
Mysql > CREATE TABLE double_test (- > m DOUBLE (10Power6),-> g DOUBLE (10L6)->) ENGINE=INNODB CHARSET=utf8mb4;Query OK, 0 rows affected (0.08 sec)
* insert m and g data
Mysql > INSERT INTO double_test SELECT 3.1415 2.1542 * Records: 1 Duplicates: 0 Warnings: 0mysql > select * from double_test +-+-+ | m | g | +-+-+ | 3.141500 | 2.154200 | +-+-+ 1 row in set (2.154200 sec)
* perform M / G * G operations
Mysql > SELECT m / g * g, m FROM double_test;+-+-+ | m / g * g | m | +-+-+ | 3.1415000000 | 3.141500 | +-+-+ 1 row in set (sec)
* High precision (decimal) applications
* create decimal_test table
Mysql > CREATE TABLE decimal_test (- > m DECIMAL (10 sec 6),-> g DECIMAL (10 rows affected 6)->) ENGINE=INNODB CHARSET=utf8mb4;Query OK, 0 rows affected (0.05 sec)
* insert m and g data
Mysql > INSERT INTO decimal_test SELECT 3.1415 2.1542 * Records: 1 Duplicates: 0 Warnings: 0mysql > SELECT * FROM decimal_test +-+-+ | m | g | +-+-+ | 3.141500 | 2.154200 | +-+-+ 1 row in set (2.154200 sec)
* perform M / G * G operations
Mysql > SELECT m / g * g, m FROM decimal_test +-+ | m / g * g | m | +-+ | 3.1415000000000000 | 3.141500 | +-+-+ 1 row in set (0.00 sec)
4. Summary of floating-point type application
* if the floating point number does not write precision and scale, it will be displayed according to the actual situation.
* if there is precision and scale, the data will be rounded and inserted, and the system will not report an error.
* if DECIMAL does not set precision and scale, it just operates in accordance with the default (10d0). If the data exceeds the precision and scale value, an error will be reported.
* accounts and accounting systems must use DECIMAL types to determine accuracy and financial security.
5. Summary
In order to demand-driven technology, there is no difference in technology itself, only in business.
For the above on the MySQL data floating-point type of the practical application operation, we do not think it is very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.