In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article is to share with you about the role of float and decimal types in MySQL, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Float,double is prone to errors. When accuracy is high, it is recommended to use decimal. Decimal is stored as a string in mysql memory and is used to define data with high currency accuracy. In data migration, float (MForce D) is a non-standard definition, and it is best not to use it in this way. M is the precision and D is the scale.
Mysql > create table T1 (C1 float (10Magne2), c3 decimal (10Magne2))
Query OK, 0 rows affected (0.02 sec)
Mysql > insert into T1 values (1234567.23, 1234567.23)
Query OK, 1 row affected (0.01sec)
Mysql > select * from T1
+-+ +
| | C1 | c3 |
+-+ +
| | 1234567.25 | 1234567.23 | |
+-+ +
1 row in set (0.02 sec)
Mysql > insert into T1 values (9876543.21, 9876543.12)
Query OK, 1 row affected (0.00 sec)
Mysql >
Mysql > select * from T1
+-+ +
| | C1 | c3 |
+-+ +
| | 1234567.25 | 1234567.23 | |
| | 9876543.00 | 9876543.12 | |
+-+ +
2 rows in set (0.00 sec)
When the precision and scale of fload and double are not defined, the storage is stored according to the given value, which is related to OS and the current hardware.
Decimal defaults to decimal (1010 0)
Because of the error problem, in the program, less floating-point numbers are used for = comparison, and range comparison can be done. For numeric comparisons, it is best to use the decimal type.
In precision, symbols are not counted:
Mysql > insert into T1 values (- 98765430.21,-98765430.12)
Query OK, 1 row affected (0.01sec)
Mysql > select * from T1
+-+ +
| | C1 | c3 |
+-+ +
| | 1234567.25 | 1234567.23 | |
| | 9876543.00 | 9876543.12 | |
| |-98765432.00 |-98765430.12 | |
+-+ +
3 rows in set (0.00 sec)
Float occupies 4 bytes, double takes 8 bytes, and decimail (MMagazine D) occupies 2 bytes.
The decimal type can accurately represent very large or very precise decimals. Numbers up to 1028 (positive or negative) and up to 28 significant digits can be stored as decimal types without losing their accuracy. This type is useful for applications that must avoid rounding errors, such as accounting.
Float is a floating point number and cannot specify decimal places.
Decimal is an exact number, and precision can be specified.
For mysql 5, the maximum p of decimal (pforce s) is 65 and the maximum of S is 30.
The decimal data type, which can store up to 38 numbers, stores an accurate (accurate) numerical representation and does not store approximations of values.
When data values must be stored exactly as specified, decimal data types with decimals can be used to store numbers.
Float and real data types are called approximate data types. Exact values are not stored. These data types are not used when precise numerical status is required, such as in financial applications, in operations that need to be rounded, or in operations where equivalence checks are performed. Use the integer, decimal, money, or smallmone data types at this point.
In WHERE clause search conditions, especially the = and operators, you should avoid using float or real columns. It is best to limit the use of float and real columns to compare > or <.
The above is the role of float and decimal types in MySQL. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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: 259
*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.