How can I solve the difference between the value calculated by Mysql and that calculated by the calculator!

Source: Internet
Author: User
How can I solve the difference between the value calculated by Mysql and that calculated by the calculator! Such as This SQL. CjPrice is 600. in this case, cjNum is 5.97.

The preceding SQL statement calculates 3581.9998741149902 and the calculator calculates 3582.

What problems do I get when I run the following SQL statement in phpmyadmin?

Select sum (600*5.97), which is also 3582


How can this problem be solved ~~~


Reply to discussion (solution)

If your cjNum is not of the DECIMAL type, apply the round to obtain the result.

Float is used for field types.
Inaccurate single precision
If you have high precision requirements, we recommend that you replace them with double, decimal, and numeric.
Double type, which is less efficient, but more accurate
Decimal and numeric are almost equivalent. specific precision must be specified.

Your query result is related to the two field types multiplied by your number.

CjPrice integer cjNum Float type
Execution in phpmysql is the same as that in mysql, with decimal places.

Maybe it has something to do with the version,
Try select round (SUM (cjPrice * cjNum), 2) from ..
Retain two decimal places

Indeed, my cjPrice is decimal cjNum and float. I can change cjNum to decimal.

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.