Bug #81035 `NEWDECIMAL` result for ROUND() function is out of range of 65 digits
Submitted: 12 Apr 2016 1:57 Modified: 12 Apr 2016 7:42
Reporter: Su Dylan Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.7.8, 5.5.49, 5.6.30, 5.7.12 OS:Any
Assigned to: CPU Architecture:Any

[12 Apr 2016 1:57] Su Dylan
Description:
Output:
==
mysql> select round(999999999999999999999999999999999999999999999199999999999999999999999999999999999,-36);
Field   1:  `round(999999999999999999999999999999999999999999999199999999999999999999999999999999999,-36)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     82
Max_length: 81
Decimals:   0
Flags:      NOT_NULL BINARY

+----------------------------------------------------------------------------------------------+
| round(999999999999999999999999999999999999999999999199999999999999999999999999999999999,-36) |
+----------------------------------------------------------------------------------------------+
|            999999999999999999999999999999999999999999999000000000000000000000000000000000000 |
+----------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select round(9999999999999999999999999999999999999999999991999999999999999999999999999999999998,-37);
Field   1:  `round(9999999999999999999999999999999999999999999991999999999999999999999999999999999998,-37)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     66
Max_length: 66
Decimals:   0
Flags:      NOT_NULL BINARY

+-----------------------------------------------------------------------------------------------+
| round(9999999999999999999999999999999999999999999991999999999999999999999999999999999998,-37) |
+-----------------------------------------------------------------------------------------------+
|                            100000000000000000000000000000000000000000000000000000000000000000 |
+-----------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

Problem:
==
From the following menual:
https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html
we can see that max value for decimal is 65 digit. 
However, in the first select the result `999999999999999999999999999999999999999999999000000000000000000000000000000000000` contains 82 digits, which has already out of range of decimal, but the type in `column-type-info` is `NEWDECIMAL`.

How to repeat:
select round(999999999999999999999999999999999999999999999199999999999999999999999999999999999,-36);
select round(9999999999999999999999999999999999999999999991999999999999999999999999999999999998,-37);

Suggested fix:
Truncation is expected for first select, to 65 digits.
[12 Apr 2016 7:42] Umesh Shastry
Hello Su Dylan,

Thank you for the report and test case.
Observed this with 5.5.49, 5.6.30 and 5.7.12.

Thanks,
Umesh