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

What are the types of mysql decimals available

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Xiaobian to share with you what types of mysql decimals are available, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

Available types of mysql decimals: 1. FLOAT type, which can store single-precision floating-point numbers;2. DOUBLE type, which can store double-precision floating-point numbers;3. DECIMAL type, which is used to store precise numerical values, such as monetary data in accounting systems.

Operating environment of this tutorial: Windows 7 system, MySQL8 version, Dell G3 computer.

MySQL uses floating-point numbers and fixed-point numbers to represent decimals.

There are two types of floating-point numbers, single-precision floating-point numbers (FLOAT) and double-precision floating-point numbers (DOUBLE); there is only one fixed-point type, DECIMAL.

Both floating-point and fixed-point types can be represented by (M, D), where M is precision and represents the total number of digits, and D is scale and represents the number of decimal digits.

Floating-point number types range from M (1~255) and D (1~30, and cannot be greater than M-2), indicating display width and decimal places, respectively. M and D are optional in FLOAT and DOUBLE, and the FLOAT and DOUBLE types will be saved to the maximum precision supported by the hardware. DECIMAL has a default D value of 0 and M value of 10.

The following table lists the decimal types and storage requirements in MySQL.

DECIMAL type is different from FLOAT and DOUBLE. DOUBLE is actually stored in the form of a string. The maximum possible range of DECIMAL is the same as DOUBLE, but the valid range of values is determined by M and D. If M is changed and D is fixed, the range of values will increase as M increases.

As can be seen from the above table, DECIMAL's storage space is not fixed, but is determined by the precision value M, occupying M+2 bytes.

The FLOAT type has the following values:

Signed values range from-3.402823466E+38 to-1.175494351E-38.

Unsigned values range from 0 and-1.175494351E-38 to-3.402823466E +38.

The range of DOUBLE values is as follows:

Signed values range from-1.7976931348623157E+308 to-2.2250738585072014E-308.

Unsigned values range from 0 and-2.2250738585072014E-308 to-1.7976931348623157E +308.

Note: Whether fixed-point or floating-point, if the precision specified by the user exceeds the precision range, it will be rounded.

FLOAT and DOUBLE default to actual precision when precision is not specified, DECIMAL defaults to (10, 0) when precision is not specified.

The advantage of floating-point numbers over fixed-point numbers is that they can represent a larger range for a given length; the disadvantage is that they cause precision problems.

DECIMAL type

The DECIMAL data type is used to store precise numerical values in a database. We often use the DECIMAL data type for columns that preserve accuracy, such as monetary data in accounting systems.

To define a column of data type DECIMAL, use the following syntax:

column_name DECIMAL(P,D);

In the syntax above:

P is the precision with which the number of significant digits is expressed. P ranges from 1 to 65.

D is the number of digits after the decimal point. D ranges from 0 to 30. MySQL requires D to be less than or equal to (

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