The type of float for MySQL is strange, 2 values are not equal solution

Source: Internet
Author: User
The type of float for MySQL is strange, 2 values are not equal
The table has a lot of data, but a few are strange, the field is float type, 2 values are the same

Payment value =299.7
Feiyong value =299.7

Query statement: feiyong>0 and Payment>0 and Payment

At this point can still query out, and just a few have this problem, the others are normal

------to solve the idea----------------------
Floating-point numbers represent a large number, missing part of the precision
So apply when comparing: a strategy that is equal when the absolute value of the difference of two numbers is less than a certain minimum number
Or use round to obtain a valid number after comparing
If your application needs to have a precise number of decimal digits (such as finance) then you should use the DECIMAL type
------to solve the idea----------------------
This is still quite normal. After all, float data has no way of guaranteeing the accuracy of the data.
------to solve the idea----------------------
Suggested modification type is decimal
------to solve the idea----------------------

Select ..., (Payment-feiyong) as a
Form ...
...
where Feiyong>0 and payment>0
Having a > 1e-5
  • 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.