The DECIMAL data type in MySQL is used to represent precise decimal and monetary values. Its features include: accurately storing decimals and not affected by rounding errors of floating point data. The range depends on the precision value, for example DECIMAL(10, 2) ranges from -9999999999.99 to 9999999999.99. More efficient than floating point data types because fewer bits are stored.
Usage of DECIMAL data type in MySQL
The DECIMAL data type is used to represent precise decimal and monetary values. It is more suitable than floating point data types in most cases.
Syntax
<code class="sql">DECIMAL(precision, scale)</code>
Example
<code class="sql">CREATE TABLE sales ( price DECIMAL(10, 2) );</code>
This will create a table named sales
where the price
field is a DECIMAL data type, the total number of digits is 10, and there are 2 digits after the decimal point.
Features
value. For example,
DECIMAL(10, 2) ranges from -9999999999.99 to 9999999999.99.
Best Practices
When using the DECIMAL data type, consider the following best practices: and
scale to avoid unnecessary waste of storage space.
.
The above is the detailed content of How to use decimal in mysql. For more information, please follow other related articles on the PHP Chinese website!