#27744 [Com]: 141.23 - 141.00 = 0.22999999999999 ?
| From: | garbo_doe at hotmail dot com | Date: | Wed, 31 Mar 2004 11:41:40 +0000 |
| Subject: | #27744 [Com]: 141.23 - 141.00 = 0.22999999999999 ? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-57206@lists.php.net to get a copy of this message | ||
ID: 27744
Comment by: garbo_doe at hotmail dot com
Reported By: t dot steve at ariadne-quatra dot com
Status: Bogus
Bug Type: Math related
Operating System: *
PHP Version: *
New Comment:
echo (string)(75000.00 - 74999.00); returns 1, not 0.9999999999. Is
this a bug then? ;)
"Guys, how in the world is PHP supposed to magically guess what
precision you want results displayed in."
Maybe a magicless solution would be: don't use greater precision then
either the minuend or subtrahend (the one with greatest precision).
Thanks for you answers and for PHP - it's great! :-)
(I hope I'm not too annoying continuing this discussion...I sense some
irritation, "we have already explained", on this matter :-)
Previous Comments:
------------------------------------------------------------------------
[2004-03-31 03:12:23] helly@php.net
Since you don't believe us:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
------------------------------------------------------------------------
[2004-03-30 21:40:21] gschlossnagle@php.net
Floating point values in computers are never exact.
It's a fact of life, and an issue that is not only
encountered with PHP but other languages as well.
------------------------------------------------------------------------
[2004-03-30 21:35:54] t dot steve at ariadne-quatra dot com
Hi!
I am sure I am something, apologies for that. :(
"Guys, how in the world is PHP supposed to magically guess what
precision you want results displayed in."
141.23 - 141 _is_ precisely 0.23. If I was asking for 1/3, then I would
understand the decimal places. But how come 141.23-141 turns out to
have so many decimal places in the end instead of just being 0.23 - the
mathematically correct and precise result?
------------------------------------------------------------------------
[2004-03-30 19:59:05] rasmus@php.net
Guys, how in the world is PHP supposed to magically guess what
precision you want results displayed in. If you know you always want
lower precision, set that in your php.ini file. Or if you just want it
temporarily simply do:
$old = ini_set('precision',2);
echo (string)(750 - 749.99);
ini_set('precision',$old);
------------------------------------------------------------------------
[2004-03-30 19:47:47] alan_k@php.net
create table a ( b float,c float );
Query OK, 0 rows affected (0.11 sec)
mysql> insert into a (b,c) values (141.23,141);
Query OK, 1 row affected (0.07 sec)
mysql> select b-c from a;
+------------------+
| b-c |
+------------------+
| 0.22999572753906 |
+------------------+
1 row in set (0.00 sec)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/27744
--
Edit this bug report at http://bugs.php.net/?id=27744&edit=1