The difference between MySQL float and decimal.

Source: Internet
Author: User

Think of a question:

1/3+1/3+1/3=1.0

0.3+0.3+0.3 =0.9

Think about what it means to be 1/3 in a decimal world! Its approach is to take a 1/3 very close to the decimal place, as in the example above the 0.3来 instead of 1/3, so the problem is to be stored in 3 1/3 out of only 0.9.

Maybe you feel like 1/3. This number is too special. It has no number, the approximate value is also no way to replace. But you know what? In the binary world 0.1 Such numbers are not exactly stored (float), and if you do not understand it, see the IEEE 754 standard. A 0.1 example is given below.

CREATE table t (x float); INSERT into t (x) values (0.1);

CREATE table t2 (x decimal); INSERT into T2 (0.1);

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------

Decimal is stored as a character, and its accuracy is not lost.

The difference between MySQL float and decimal.

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.