Bug #111878 SELECT ROUND(X,D) result below expection
Submitted: 25 Jul 2023 9:57 Modified: 25 Jul 2023 12:23
Reporter: liu kaiyang Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0.32 OS:Any
Assigned to: CPU Architecture:Any

[25 Jul 2023 9:57] liu kaiyang
Description:
The High version does not meet expectations when using function round(X,D) to output values ​​with more than four decimal places, Suspected bug introduced by the new version.

Example:

mysql [localhost:8018] {root} ((none)) > select round(1/3,9);
+--------------+
| round(1/3,9) |
+--------------+
|  0.333333333 |
+--------------+
1 row in set (0.00 sec)

mysql [localhost:8018] {root} ((none)) > select 1/3;
+--------+
| 1/3    |
+--------+
| 0.3333 |
+--------+
1 row in set (0.00 sec)

------------------- new version output----------------------------

mysql [localhost:8032] {root} ((none)) > select round(1/3,9);
+--------------+
| round(1/3,9) |
+--------------+
|       0.3333 |
+--------------+
1 row in set (0.00 sec)

mysql [localhost:8032] {root} ((none)) > select round(1.0/3,9);
+--------------------+
| round(1.00000/3,9) |
+--------------------+
|        0.33333     |
+--------------------+
1 row in set (0.00 sec)

mysql [localhost:8032] {root} ((none)) > select 1/3;
+--------+
| 1/3    |
+--------+
| 0.3333 |
+--------+
1 row in set (0.00 sec)

-------------------------------------------------

It is speculated that the version that introduced the problem is as follows:

changed version:https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-22.html
Commit:https://github.com/mysql/mysql-server/commit/0caa1d0dab0ade24abeb2e87bffb7c04e4420789

How to repeat:
At present, only 4 decimal places can be reserved by default. Temporarily use the following temporary solution to avoid. 
In the case of using 9 decimal places, add 5 decimal places to the numerator by default.

Example:

mysql [localhost:8032] {root} ((none)) > select round(1.00000/3,9);
+--------------------+
| round(1.00000/3,9) |
+--------------------+
|        0.333333333 |
+--------------------+
1 row in set (0.00 sec)
[25 Jul 2023 12:23] MySQL Verification Team
Hi Mr. kaiyang,

Thank you for your bug report.

However, we can not repeat your report.

It works just fine with 8.0.34 and 8.1.0:

+-----------------------------+
| round(1.000000 / 3.0000, 9) |
+-----------------------------+
|                 0.333333333 |
+-----------------------------+

Do note that you made mistake by using integer 3 instead of the floating point 3.00000.

Not a bug.