Bug #9970 mysql chooses wrong number of digits behind decimal dot, for division
Submitted: 18 Apr 2005 10:33 Modified: 26 Jul 2005 9:51
Reporter: Martin Friebe (Gold Quality Contributor) (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.11 OS:Any (*)
Assigned to: Alexey Botchkov CPU Architecture:Any

[18 Apr 2005 10:33] Martin Friebe
Description:
select 1/1000;
+--------+
| 1/1000 |
+--------+
|   0.00 |
+--------+
select 1/7;
+------+
| 1/7  |
+------+
| 0.14 |
+------+

this should not be rounded, to two digits, i have looked at http://dev.mysql.com/doc/mysql/en/arithmetic-functions.html but couldnt find anything stating, the number of digits after the decimal dot would be limited.

Mysql seems to add always 2 extra digit to the maxmum amount used by any number in the expression
select 1/10000.0;
+-----------+
| 1/10000.0 |
+-----------+
|     0.000 |
+-----------+

mysql> select 1.0/10000;
+-----------+
| 1.0/10000 |
+-----------+
|     0.000 |
+-----------+

It should not limit the number of digits after the decimal point, in any division.

This could be related to the fact that mysql seems to limit the number of post decimal digits in other operations (like 2-0.4), which would produce more digits due to the decimal/dual conversion. But in a division this can not be predicted.

How to repeat:
select 1/1000;
select 1/7;

Suggested fix:
do not limit the output of post decimal digits, in a division
[26 Jul 2005 9:49] Alexey Botchkov
Thank you for taking the time to report a problem.  Unfortunately
you are not using a current version of the product your reported a
problem with -- the problem might already be fixed. Please download
a new version from http://www.mysql.com/downloads/

If you are able to reproduce the bug with one of the latest versions,
please change the version on this bug report to the version you
tested and change the status back to "Open".  Again, thank you for
your continued support of MySQL.
[26 Jul 2005 9:51] Alexey Botchkov
Sorry, this is the usual behaviour for versions earlier than 5.0
Since 5.0 you can manage the precision of the division