Bug #33402 ROUND with decimal and non-constant cannot round to 0 decimal places
Submitted: 20 Dec 2007 13:41 Modified: 21 Dec 2007 16:17
Reporter: Martin Hansson Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.0, 5.1, 6.0 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[20 Dec 2007 13:41] Martin Hansson
Description:
ROUND(X, D) rounds but does not change number of decimal places if D = 0 and D is not a constant. 

How to repeat:
CREATE TABLE t1 ( a DECIMAL(5, 4), b INT );
INSERT INTO t1 VALUES (1.2345, 0), (1.2345, 1);
SELECT a, b, ROUND(a, b) FROM t1;
/*
+--------+------+-------------+
| a      | b    | ROUND(a, b) |
+--------+------+-------------+
| 1.2345 |    0 |      1.0000 |
| 1.2345 |    1 |         1.2 |
+--------+------+-------------+
*/

Suggested fix:
Patch will follow shortly ;-)
[20 Dec 2007 15:57] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/40276

ChangeSet@1.2546, 2007-12-20 16:31:19+01:00, mhansson@linux-st28.site +3 -0
  Bug #33402: ROUND with decimal and non-constant cannot
  round to 0 decimal places
  
  The ROUND( X, D ) function did not work if X was DECIMAL andd D was a 
  non-constant equal to 0.
  Fixed by including 0 in the range of valid values for D.
[21 Dec 2007 16:17] Martin Hansson
This bug will be fixed as part of the fix for bug#33143
[24 Jan 2008 11:56] Bugs System
Pushed into 6.0.5-alpha
[24 Jan 2008 12:01] Bugs System
Pushed into 5.1.24-rc
[24 Jan 2008 12:02] Bugs System
Pushed into 5.0.56