ID: 27744 User updated by: t dot steve at ariadne-quatra dot com Reported By: t dot steve at ariadne-quatra dot com Status: Bogus Bug Type: Math related Operating System: * PHP Version: * New Comment:
Guys, guys, guys... :) I want to make one thing clear: No offense was meant, and I still think PHP is great, and that I learned something new - even though I think this is probably not the correct forum for that. :) I never imagined this would turn out to be such a long discussion - it seems I accidentally touched on something that others came across too. Just as pont of interest: We also use PHP for our (travel agency..) intra+extranet admin system, and among other things, we use PHP-generated forms to order hotel rooms for our clients. At times we get forms requesting a hotel room for "3.9999999.. nights...". :)) Now I know why. Thanks again for all the reactions, and keep up the excellent work! :) Previous Comments: ------------------------------------------------------------------------ [2004-03-31 10:28:25] [EMAIL PROTECTED] For a computer there is simply no such thing as exactly 0.23, it is as simple as that. When displaying floating point numbers, either use printf() and specify the number of significant digits you want or use PHP's precision setting. As for this suggestion: > Maybe a magicless solution would be: don't use greater > precision then either the minuend or subtrahend (the one > with greatest precision). Reducing precision during the calculation would magnify rounding errors greatly when doing a series of operations on the floating point values. You want to apply lower precision at the end at display time, not during the calculation. And at display time we don't know what the precicion of the operands were that led to this value which is why you need to explicitly express what precision you want values displayed at. ------------------------------------------------------------------------ [2004-03-31 06:41:40] garbo_doe at hotmail dot com 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 :-) ------------------------------------------------------------------------ [2004-03-31 03:12:23] [EMAIL PROTECTED] Since you don't believe us: http://docs.sun.com/source/806-3568/ncg_goldberg.html ------------------------------------------------------------------------ [2004-03-30 21:40:21] [EMAIL PROTECTED] 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? ------------------------------------------------------------------------ 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