Bug #41130 TRUNCATE changes the value of value
Submitted: 30 Nov 2008 6:11 Modified: 1 Dec 2008 5:14
Reporter: mike nimer Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:4.1.22 OS:Windows
Assigned to: CPU Architecture:Any

[30 Nov 2008 6:11] mike nimer
Description:
Truncating a number will change the value. For instance, in this query the value should be .60, but after I try to truncate the query to 2 decimal places the value becomes .59. So somehow 60% of 1, is now 59. 

How to repeat:

select (1 * .6) as total1, TRUNCATE( (1 * .6), 2) as total2

the value of 1 or 2 are wrong. But value of 3 or 5.. are correct.
[30 Nov 2008 18:30] Valeriy Kravchuk
Thank you for a problem report. What exact version, 5.0.x, do you use? Look:

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -proot -P3308 test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.72-enterprise-gpl-nt MySQL Enterprise Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select (1 * .6) as total1, TRUNCATE( (1 * .6), 2) as total2;
+--------+--------+
| total1 | total2 |
+--------+--------+
|    0.6 |   0.60 |
+--------+--------+
1 row in set (0.13 sec)
[30 Nov 2008 19:08] mike nimer
I was wrong, my server is running version 4.1.22
[1 Dec 2008 5:14] Valeriy Kravchuk
Still can not repeat the behaviour described:

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -proot -P3306 test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 4.1.22-community-nt-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select (1 * .6) as total1, TRUNCATE( (1 * .6), 2) as total2;
+--------+--------+
| total1 | total2 |
+--------+--------+
|    0.6 |   0.60 |
+--------+--------+
1 row in set (0.16 sec)
[5 Dec 2008 15:51] mike nimer
Here is a screen shot of the error, when I run the sql.

Attachment: mysqlerror.jpg (image/pjpeg, text), 34.23 KiB.