Rounding in MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Acharis
Forum Newbie
Posts: 4
Joined: Sat Jan 16, 2010 2:16 pm

Rounding in MySQL

Post by Acharis »

Why is this not working?
"UPDATE table SET value=truncate(2.33612e+006, 2)"

Is MySQL unable to round very small floats or floats of high precision?
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Rounding in MySQL

Post by Eric! »

I would guess that is is working as you have no decimals to truncate.

[text]mysql> select truncate(2.33612e+006, 2);
+---------------------------+
| truncate(2.33612e+006, 2) |
+---------------------------+
| 2336120.00 |
+---------------------------+
1 row in set (0.00 sec)
[/text]
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Rounding in MySQL

Post by twinedev »

You have to remember Truncate is working with the FULL number, I have a feeling you were wanting it to be 2.33e+06, that is just a visual representation, not the actual value it acts upon.
Post Reply