> I found different round result at below
> mysql> select round(1.235,2);
> +----------------+
> | round(1.235,2) |
> +----------------+
> |           1.24 |
> +----------------+
> 1 row in set (0.00 sec)
>
> mysql> select round(1.325,2);
> +----------------+
> | round(1.325,2) |
> +----------------+
> |           1.32 |
> +----------------+
> 1 row in set (0.00 sec)
> What does it mean?? I wonder that round must increase the front value 1
> step, but the second command show the wrong value.  Please help me correct
> round function or any idea to fixed with coding.
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)


Sommai,
May I draw your attention to the list's message footer (immediately above)

Here's the text from the relevant part of the manual 
(~~~/manual_Reference.html#Functions):-
-----
ROUND(X)
Returns the argument X, rounded to the nearest integer:
mysql> select ROUND(-1.23);
        -> -1
mysql> select ROUND(-1.58);
        -> -2
mysql> select ROUND(1.58);
        -> 2

Note that the behavior of ROUND() when the argument is half way between two integers 
depends on the C library
implementation. Some round to the nearest even number, always up, always down, or 
always towards zero. If you need one
kind of rounding, you should use a well-defined function like TRUNCATE() or FLOOR() 
instead.

ROUND(X,D)
Returns the argument X, rounded to a number with D decimals. If D is 0, the result 
will have no decimal point or
fractional part:
mysql> select ROUND(1.298, 1);
        -> 1.3
mysql> select ROUND(1.298, 0);
        -> 1
-----

Your observation probably has something to do with the rounding of decimal numbers 
(per 1.325) into binary numbers.

In 'the good old days' when you worked right down 'under the hood' of the machine, it 
was possible to load zero into
storage, and then set up a loop adding 0.1 until the value=1.0 - and the loop would 
never end! [in today's parlance:
x=0; while ( x <> 1.0 ) do x = x + 0.1; ] That's the 'fun part' of approximating 
decimal calculations in binary!
Actually, I haven't tried that ComSc 101-type problem out recently. Does it still 
happen or our are 'modern tools'
sufficiently smart?

Regards,
=dn




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to