Bug #61676 Result of DIV with Decimal and Integer does not make sense
Submitted: 28 Jun 2011 15:54 Modified: 24 Sep 2011 16:48
Reporter: Jun Yao Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Data Types Severity:S2 (Serious)
Version:5.5.11 OS:Windows (XP, 7)
Assigned to: CPU Architecture:Any
Tags: regression

[28 Jun 2011 15:54] Jun Yao
Description:
(5 DIV 2) and (5.0 DIV 2) results in different values.  This is not the same behavior in MySQL 5.0 version, in which results seem to make more sense.

How to repeat:
SELECT 5 DIV 2;

Result = 2

SELECT 5.0 DIV 2;

Result = 3

Suggested fix:
Since the documentation states that DIV is similar to FLOOR, after the decimal division, maybe FLOOR should be used instead of rounding to the nearest integer.
[28 Jun 2011 16:00] Jun Yao
In 5.1, results are also consistent.  Both (5.0 div 2) and (5 div 2) equal 2.
[29 Jun 2011 7:13] Valeriy Kravchuk
Thank you for the bug report. Verified just as described. Looks like regression comparing to 5.1.x.
[24 Sep 2011 16:48] Paul DuBois
Noted in 5.5.16, 5.6.3 changelogs.

(5 DIV 2) and (5.0 DIV 2) produced different results (2 versus 3)
because the result of the latter expression was not truncated before
conversion to integer. This differed from the behavior in MySQL 5.0
and 5.1. Now both expressions produce 2.