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.