On 23 Jan 2004 at 12:13, Andrew Kuebler wrote:

> Can anyone explain why:
> 
> SELECT ROUND(.012345, 5)
> -> .01234
> 
> Why doesn't mysql round the 5 up to .01235? How do I get it to round
> up? I've tried manipulating ceil, floor, round and truncate and I
> can't seam to find an easy way to do this.

This comment from the documentation on TRUNCATE applies to other 
functions as well:

| Note that as decimal numbers are normally not stored as exact 
| numbers in computers, but as double-precision values, you may be
| fooled by the following result:
|
| mysql> SELECT TRUNCATE(10.28*100,0);
|        -> 1027
|
| The above happens because 10.28 is actually stored as something
| like 10.2799999999999999.

That's how floating-point numbers work generally, not just in MySQL.
Why are you so concerned about it?  Presumably your 0.012345 isn't an 
exact number but a measurement of some sort, so it could just as well 
be 0.0123449 or 0.0123451, and 0.01234 is perfectly fine as a rounded 
value.

If you do have exact numbers with six decimal places, you're probably 
better off storing them as some sort of integer and adding the 
decimal point when necessary for display.

-- 
Keith C. Ivey <[EMAIL PROTECTED]>
Tobacco Documents Online
http://tobaccodocuments.org


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to