Bug #1639 TRUNCATE(n, 0) command rounding number down
Submitted: 23 Oct 2003 12:16 Modified: 27 Oct 2003 0:52
Reporter: Kimberly Newell Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:3.23.56 OS:Linux (Red Hat Linux-gnu (i386))
Assigned to: Sergei Glukhov CPU Architecture:Any

[23 Oct 2003 12:16] Kimberly Newell
Description:
The TRUNCATE() command to eliminate decimal points is rounding the whole number down by one

How to repeat:
Here is a code snippet that I've actually tested.  I've searched through the bug lists and can't find anything that indicates that this is a known issue.

-- MySQL Code tested in version 3.23.56
-- MySQL Return Value = 24
select TRUNCATE( ((145/60)-TRUNCATE(145/60,0))*60, 0);

-- Oracle Code
-- Oracle Return Value = 25
select TRUNC( ((145/60)-TRUNC(145/60,0))*60, 0) FROM DUAL;
[23 Oct 2003 13:47] Dean Ellis
Also occurs in 4.0.16 and 4.1.1.
[27 Oct 2003 0:52] Sergei Glukhov
There are "exact numeric types" and "approximate numeric types".
Exact numeric value is a fixed-point number in the standard
Approximate numeric value A has mantissa M and exponent E. The value M*10^E is "apparent" value of the A. it's actual value is approximately it's apparent value.
The thing is that MySQL - unlike Oracle - does not support exact numeric values with the scale > 0, does not support *yet*, that is.
Oracle probably treats these numbers as fixed-point numbers.