-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Result of function ROUND(x, d)
is different from MySQL
#26993
Comments
mysql: MySQL root@172.16.5.103:(none)> select round(49.99999, -2);
+---------------------+
| round(49.99999, -2) |
+---------------------+
| 0 |
+---------------------+
1 row in set
Time: 0.047s
MySQL root@172.16.5.103:(none)> select round(50, -2);
+---------------+
| round(50, -2) |
+---------------+
| 100 |
+---------------+
1 row in set
Time: 0.061s
MySQL root@172.16.5.103:(none)> select round(50.00001, -2);
+---------------------+
| round(50.00001, -2) |
+---------------------+
| 100 |
+---------------------+
1 row in set
Time: 0.051s tidb: mysql> select round(49.99999, -2);
+---------------------+
| round(49.99999, -2) |
+---------------------+
| 0 |
+---------------------+
1 row in set (0.00 sec)
mysql> select round(50, -2);
+---------------+
| round(50, -2) |
+---------------+
| 0 |
+---------------+
1 row in set (0.00 sec)
mysql> select round(50.00001, -2);
+---------------------+
| round(50.00001, -2) |
+---------------------+
| 100 |
+---------------------+
1 row in set (0.00 sec)
|
/assign |
I think this should have the type/compatibility label |
I found more test cases to show discrepancies. select round(-5000111000111000155,-1);
select round(15000111000111000155,-1);
select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614));
select round(1.5, 2147483640), truncate(1.5, 2147483640); |
I'm adjusting the severity to moderate. |
Both MySQL and Postgres return 370, but TiDB return 360
Currently, the |
This is the result in ClickHouse:
And SQLite3:
Note that for Oracle you need to add Also tried SQL Server 2022, that gives the same result as SQL Server 2017. |
This is what Python does:
Not sure what the correct result is but 370/370 seems to be very common. |
Note that for SQLite the manual has this, which explains the unexpected results. "The round(X,Y) function returns a floating-point value X rounded to Y digits to the right of the decimal point. If the Y argument is omitted or negative, it is taken to be 0." |
I also tried Apache Derby... but Derby doesn't have a |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: