MySQL floating-point and fixed-point numbers

Source: Internet
Author: User

Floating-point numbers are typically used to represent numeric values that contain fractional parts. When a field is defined as a floating-point type, if the precision of the inserted data exceeds the actual precision defined by the column, the insertion value is rounded to the actual defined precision value, and then inserted
The rounding process is not an error. float, double (or real) is used in MySQL to represent floating-point numbers.

Fixed-point numbers are different from floating-point numbers, and the fixed-point number is actually stored as a string, so the fixed-point number can save data more accurately.

mysql> CREATE TABLE Test (C1 float (10,2), C2 decimal (10,2));
Query OK, 0 rows affected (0.29 sec)
mysql> INSERT into test values (199999.82,199999.82);
Query OK, 1 row affected (0.07 sec)
Mysql> select * from test;
+-------------+-------------+
| C1 | C2 |
+-------------+-------------+
| 199999.81 | 199999.82|
+-------------+-------------+

MySQL floating-point and fixed-point numbers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.