Current location - Loan Platform Complete Network - Big data management - What data type is more reliable for mysql to store amount types, and what data type is used for general enterprise data?
What data type is more reliable for mysql to store amount types, and what data type is used for general enterprise data?

For tokens such as game coins, it is generally feasible to store them as int type. The problem is crossing the boundary, the int type is 11 bits long.

When storing RMB-related amounts, then you can only store up to 9 lengths of RMB, which means that you can only store a maximum of 999,999,999,999, less than 1 billion values, which leaves you with a hidden problem if your business grows quickly.

Decimal: Decimal is a data type designed specifically for finance-related issues.

DECIMAL was introduced from MySQL 5.1 with the column declaration syntax DECIMAL(M,D). In MySQL 5.1, the range of values for the parameter is as follows: M is the maximum number of digits (precision). The range is 1 to 65 (in older MySQL versions, the allowed range is 1 to 254), and the default value of M is 10.

D is the number of digits to the right of the decimal point (scale). The range is 0 to 30, but may not exceed M. Note: float takes up 4 bytes, double takes up 8 bytes, decimail(M,D) takes up M+2 bytes.

E.g. DECIMAL(5,2) has a maximum value of 9999.99 because there are 7 bytes available. Can solve the problem of range and precision of data.

Extended Information

MySQL Data Type DECIMAL Usage:

The MySQL?DECIMAL data type is used to store exact numeric values in the database. We often use the DECIMAL data type for columns that retain exact precision, such as monetary data in accounting systems.

To define a column with the data type DECIMAL, use the following syntax: column_name?DECIMAL(P,D);

In the above syntax:

P is the precision of the number of digits that represent a valid number. ?P ranges from 1?65.

D is to indicate the number of decimal places. ?D ranges from 0 to 30. MySQL requires D to be less than or equal to (<=)P.

DECIMAL(P, D) indicates the number of P digits in which the column can store D decimal places. The actual range of the decimal column depends on the precision and scale.

Like the INT data type, the DECIMAL type has UNSIGNED and ZEROFILL attributes. If the UNSIGNED attribute is used, DECIMALUNSIGNED columns will not accept negative values.

If ZEROFILL is used, MySQL will pad the display value to 0 to display the width specified by the column definition. Also, if we use ZEROFILL for DECIMAL columns, MySQL will automatically add the UNSIGNED attribute to the column.