Re: [PHP] ROUND inconsistency

2001-04-13 Thread Yasuo Ohgaki

Correction, MySQL is not returning floor, since it returns 2 for round(1.5). - I
didn't see it.
MySQL should not return 2 for round(2.5), but it should return 3. I think it's
MySQL bug.

How about ask in MySQL mailing list?

--
Yasuo Ohgaki


""Yasuo Ohgaki"" [EMAIL PROTECTED] wrote in message
9b60qv$v9b$[EMAIL PROTECTED]">news:9b60qv$v9b$[EMAIL PROTECTED]...
 MySQL is returning floor. (I'm not a MySQL heavy user, though :)

 PHP's result is correct for its function name, I think.
 If MySQL returns floor for round(), how about use floor() in PHP?

 Regards,
 --
 Yasuo Ohgaki


 "Lee Howard" [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  Using MySQL 3.23.32 on RedHat Linux 7.0...
 
  MySQL's ROUND function rounds 5 up when the preceding digit is odd and down
  when the preceding digit is even.
 
  mysql select round(1.5);
  ++
  | round(1.5) |
  ++
  |  2 |
  ++
  1 row in set (0.00 sec)
 
  mysql select round(2.5);
  ++
  | round(2.5) |
  ++
  |  2 |
  ++
  1 row in set (0.00 sec)
 
  I think that this is technically the correct behavior, scientifically,
  anyway.  However, this is not the common "lay-man's" method of rounding,
  which is to always round 5 up, as exhibited by PHP-4.0.4pl1...
 
  ? echo round(1.5); ?
  br
  ? echo round(2.5); ?
 
  Apache 1.3.14 output for this is:
 
  2
  3
 
  This discrepancy causes a difficulty in programming PHP and MySQL together,
  for example, because all of the rounding must be done in either PHP or
  MySQL but not both partially unless you want conflicting data.
 
  I would like to see MySQL ROUND() syntax expand to be ROUND(X,D,M) where
  optional M value indicates the method of rounding, the default being the
  current method.
 
  I would also like to see PHP round() syntax expand to be
  double round (double val [, int precision] [, char method])
  where the optional method value indicates the method of rounding, the
  default being the current method.
 
  Thanks.
 
  Lee Howard
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] ROUND inconsistency

2001-04-13 Thread Philip Hallstrom

In article 9b6c4v$m41$[EMAIL PROTECTED] you write:
Correction, MySQL is not returning floor, since it returns 2 for round(1.5). - I
didn't see it.
MySQL should not return 2 for round(2.5), but it should return 3. I think it's
MySQL bug.

How about ask in MySQL mailing list?

I don't think it's just a MySQL thing... it occurs in PostgreSQL as
well...

test= select version();
version 

 PostgreSQL 7.0.3 on i386-unknown-freebsdelf4.1, compiled by gcc 2.95.2
(1 row)

test= select round(1.5);
 round 
---
 2
(1 row)

test= select round(2.5);
 round 
---
 2
(1 row)


However, you could always do floor(number + .5) to consistent
behaviour...

-philip

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] ROUND inconsistency

2001-04-12 Thread Lee Howard

Using MySQL 3.23.32 on RedHat Linux 7.0...

MySQL's ROUND function rounds 5 up when the preceding digit is odd and down
when the preceding digit is even.

mysql select round(1.5);
++
| round(1.5) |
++
|  2 |
++
1 row in set (0.00 sec)

mysql select round(2.5);
++
| round(2.5) |
++
|  2 |
++
1 row in set (0.00 sec)

I think that this is technically the correct behavior, scientifically,
anyway.  However, this is not the common "lay-man's" method of rounding,
which is to always round 5 up, as exhibited by PHP-4.0.4pl1...

? echo round(1.5); ?
br
? echo round(2.5); ?

Apache 1.3.14 output for this is:

2
3

This discrepancy causes a difficulty in programming PHP and MySQL together,
for example, because all of the rounding must be done in either PHP or
MySQL but not both partially unless you want conflicting data.

I would like to see MySQL ROUND() syntax expand to be ROUND(X,D,M) where
optional M value indicates the method of rounding, the default being the
current method.

I would also like to see PHP round() syntax expand to be 
double round (double val [, int precision] [, char method])
where the optional method value indicates the method of rounding, the
default being the current method.

Thanks.

Lee Howard


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] ROUND inconsistency

2001-04-12 Thread Yasuo Ohgaki

MySQL is returning floor. (I'm not a MySQL heavy user, though :)

PHP's result is correct for its function name, I think.
If MySQL returns floor for round(), how about use floor() in PHP?

Regards,
--
Yasuo Ohgaki


"Lee Howard" [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Using MySQL 3.23.32 on RedHat Linux 7.0...

 MySQL's ROUND function rounds 5 up when the preceding digit is odd and down
 when the preceding digit is even.

 mysql select round(1.5);
 ++
 | round(1.5) |
 ++
 |  2 |
 ++
 1 row in set (0.00 sec)

 mysql select round(2.5);
 ++
 | round(2.5) |
 ++
 |  2 |
 ++
 1 row in set (0.00 sec)

 I think that this is technically the correct behavior, scientifically,
 anyway.  However, this is not the common "lay-man's" method of rounding,
 which is to always round 5 up, as exhibited by PHP-4.0.4pl1...

 ? echo round(1.5); ?
 br
 ? echo round(2.5); ?

 Apache 1.3.14 output for this is:

 2
 3

 This discrepancy causes a difficulty in programming PHP and MySQL together,
 for example, because all of the rounding must be done in either PHP or
 MySQL but not both partially unless you want conflicting data.

 I would like to see MySQL ROUND() syntax expand to be ROUND(X,D,M) where
 optional M value indicates the method of rounding, the default being the
 current method.

 I would also like to see PHP round() syntax expand to be
 double round (double val [, int precision] [, char method])
 where the optional method value indicates the method of rounding, the
 default being the current method.

 Thanks.

 Lee Howard


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]