#33009 [Opn->Bgs]: floor does not work with some integers as argument
| From: | tony2001@php.net | Date: | Wed, 11 May 2005 19:03:47 +0000 |
| Subject: | #33009 [Opn->Bgs]: floor does not work with some integers as argument | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-78902@lists.php.net to get a copy of this message | ||
ID: 33009
Updated by: tony2001@php.net
Reported By: edelmar at ditech dot com dot br
-Status: Open
+Status: Bogus
Bug Type: *Math Functions
Operating System: Win XP
PHP Version: 4.3.11
New Comment:
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2005-05-11 20:41:00] edelmar at ditech dot com dot br
$d = 75.6 * 100;
$d = (string)$d;
echo floor($d).'<br>'; // prints 7560, wich is expected... how
embarassing.
------------------------------------------------------------------------
[2005-05-11 20:12:01] edelmar at ditech dot com dot br
Description:
------------
Using PHP Version 4.3.11 on Windows xp (my development machine).
I believe this behavior of floor function is a bug. The number 7560
passed to it is an integer and would not be changed by floor.
I am using 100 times number because PHP has no function like
'truncate'. I want 2 decimals and there is no way to do it with regular
functions.
Its like 7560 has some special properties because this error does not
happens with a lot of other numbers.
Thank you.
Reproduce code:
---------------
echo (75.6 * 100).'<br>'; // prints 7560 - OK
echo intval(75.6 * 100).'<br>'; // prints 7559 - ?
echo (int)(75.6 * 100).'<br>'; // prints 7559 - ?
echo floor(75.6 * 100).'<br>'; // prints 7559 - ?
echo ceil(75.6 * 100).'<br>'; // prints 7560 - OK
echo round(75.6 * 100).'<br>'; // prints 7560 - OK
Expected result:
----------------
7560
7560
7560
7560
7560
7560
Actual result:
--------------
7560
7559
7559
7559
7560
7560
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33009&edit=1