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 data type is used to represent mysql currency

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

In mysql, currencies are often represented by fields of types Decimal and Numric, which are implemented by MySQL as the same type; they are used to preserve values whose accuracy is extremely important, such as money-related data.

In development, currency is often represented by Decimal and Numric types in MySQL in the database, and these two types are implemented by MySQL as the same type. They are used to preserve values whose accuracy is extremely important, such as data related to money. Precision and size can be (and usually are) specified when a class is declared to be one of these types; for example:

Salary DECIMAL (9Pol 2)

In this example, 9 (precision) represents the total number of decimal places that will be used to store the value, while 2 (scale) represents the number of places after the decimal point. Therefore, in this case, the range of values that can be stored in the salary column is from-9999999.99 to 9999999.99.

DECIMAL and numeric values are stored as strings, not as binary floating-point numbers, to preserve the decimal precision of those values. A character is used for each digit of the value, the decimal point (if scale > 0), and the "-" symbol (for negative values). If scale is 0, the decimal and numeric values do not contain a decimal point or a decimal part.

Reason for not using float or double: because float and double are stored in binary, there is a certain error.

For example: in the database, the storage types of C1, decimal and float are float (10.2), decimal (10.2) and float respectively.

Insert data:

INTO test (C1 and c2) VALUES (1234567.23 and 1234567.23 and 1234567.23)

There is a certain error in using float type storage. So use the decimal or numric type.

About what data type of mysql currency is expressed here, I hope the above content can be of some help to you and can learn more knowledge. If you think the article is good, you can 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