Phpround Function bug

Source: Internet
Author: User
When calculating the growth rate, you can use round to extract the two digits after the decimal point, but when you go to the database to view the data, most of the data is acceptable, however, after debugging some errors, I found that the bug-8.04554644255644round becomes-8.04000000000001, which is quite likely to appear in another bug... when calculating the growth rate, use round to extract the last two digits of the decimal point.
However, when I went to the database to view the data, most of the data was acceptable, but some of them encountered errors.

Found after debugging
-8.04554643785644
After round becomes
-8.04000000000001

This bug is highly likely to occur.
Test in another script, and the same data is intercepted normally.

Reply content:

When calculating the growth rate, use round to extract the last two digits of the decimal point.
However, when I went to the database to view the data, most of the data was acceptable, but some of them encountered errors.

Found after debugging
-8.04554643785644
After round becomes
-8.04000000000001

This bug is highly likely to occur.
Test in another script, and the same data is intercepted normally.

It's not a bug. There must be a precision error when it comes to floating point numbers. Just pay attention to it.

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.