Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed usage and function of DECIMAL in MySQL data type

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 detailed usage and function of DECIMAL in the MySQL data type. I hope these words can bring you practical use, which is also the main purpose of this article that I edit the detailed usage and function of DECIMAL in the MySQL data type. All right, don't talk too much nonsense, let's just read the following.

The values typically assigned to floating-point columns are rounded to the decimal number specified by this column. If 1.23456 is stored in a column of FLOAT (8,1), the result is 1.2. If the same value is stored in the column of FLOAT (8,4), the result is 1.2346.

This means that floating-point columns with sufficient digits should be defined to get the most accurate values possible. If you want to be accurate to 1/1000, do not define the type to have only two decimal places.

This handling of floating-point values has an exception in MySQL3.23, and the performance of FLOAT (4) and FLOAT (8) has changed. These two types are now single-precision (4-byte) and double-precision (8-byte) types, and they are true floating-point types to the extent that their values are stored in the given form (limited by hardware only).

The DECIMAL type is different from FLOAT and DECIMAL, where DECIMAL is actually stored in strings. The maximum possible range of values for DECIMAL is the same as that of DOUBLE, but the range of valid values is determined by the values of M and D. If M is changed and D is fixed, the range of values will increase with the increase of M. The first three lines of Table 2-7 illustrate this. If M is fixed and D is changed, the range of values will become smaller with the increase of D (but the precision will increase). The last three lines of Table 2-7 illustrate this.

The range of values for a given DECIMAL type depends on the version of the MySQL data type. For previous versions of MySQL3.23, each value of the DECIMAL (M, D) column occupied M bytes, while symbols (if necessary) and decimal points were included in M bytes. Therefore, columns of type DECIMAL (5,2) range from-9. 99 to 99. 9. 9 9, because they cover all possible 5 character values.

Like MySQL3.23, DECIMAL values are processed according to the ANSI specification, which states that DECIMAL (M, D) must be able to represent any value of M digits and D decimal places.

For example, DECIMAL (5,2) must be able to represent all values from-999.99 to 999.99. And symbols and decimal points must be stored, so DECIMAL values account for M + 2 bytes since MySQL3.23. For DECIMAL (5, 2), the value of longest (- 9 9 9. 9 9) 7 bytes are required.

At one end of the positive value range, a positive sign is not required, so the MySQL data type uses it to expand the value range beyond the value range required by the ANSI specification. For example, the maximum value of DECIMAL (5,2) is 99 99 9. 9 9, because there are 7 bytes available.

In short, in MySQL3.23 and later versions, the range of values for DECIMAL (M, D) is equal to that of DECIMAL (M + 2, D) in earlier versions. In all versions of the MySQL data type, if the D of a DECIMAL column is 0, the decimal point is not stored. The result is an expanded range of values for the column, because the bytes used to store the decimal point can now be used to store other numbers.

For the above about the detailed usage and role of DECIMAL in the MySQL data type, we do not find it 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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report