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 type does decimal refer to in mysql

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

Share

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

This article will explain in detail what type decimal refers to in mysql. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Decimal is a precise data type that exists in MySQL, and the syntax format is "DECIMAL (MMagne D)". Where M is the maximum number (precision) of the number, the range is "1x 65", the default value is 10 position D is the number of digits to the right of the decimal point (scale), the range is "0" 30 ", but not more than M.

The types that support floating-point numbers in MySQL are FLOAT, DOUBLE, and DECIMAL. Unlike FLOAT and DOUBLE,DECIMAL, the DECIMAL type 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.

For things with high precision, such as money, it is recommended to use the decimal type, do not consider float,double, because they are prone to errors, numeric and decimal synonym, numeric will be automatically converted to decimal.

DECIMAL was introduced from MySQL 5. 1, and the declaration syntax for columns is DECIMAL (MMagne D). In MySQL 5.1, the range of parameters is as follows:

M is the maximum number of numbers (precision). The range is 1: 65 (in older versions of MySQL, the allowed range is 1: 254), and the default value for M is 10.

D is the number of digits to the right of the decimal point (scale). Its range is 030, but not more than M.

Description: 4 bytes for float, 8 bytes for double, and 2 bytes for decimail.

For example, the maximum value of DECIMAL (5J2) is 9999.99 because there are 7 bytes available.

Therefore, M and D are the key factors affecting the value range of DECIMAL (M, D).

Value range of type description (MySQL

< 3.23) 取值范围(MySQL >

= 3.23)

DECIMAL (4)-9.9 to 99.9-999.9 to 9999.9

DECIMAL (5Pol 1)-99.9 to 999.9-9999.9 to 99999.9

DECIMAL (6Jing 1)-999.9 to 9999.9-99999.9 to 999999.9

DECIMAL (6Pol 2)-99.99 to 999.99-9999.99 to 99999.99

DECIMAL (6p3)-9.999 to 99.999-999.999 to 9999.999

(recommended tutorial: mysql video tutorial)

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.99 because they cover all possible five-character values.

# in MySQL 3.23 and later, the value range of DECIMAL (M, D) is equal to that of DECIMAL (M + 2, D) in earlier versions.

Conclusion:

When the value is within its range and there are more decimal places, the decimal places will be truncated directly.

If the value is outside its range, it is filled with the maximum (minimum) value.

This is the end of the article on "what type of decimal in mysql". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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