note 83478 added to function.floor
| From: | greene dot mc at removethispart dot gmail dot com | Date: | Tue, 27 May 2008 20:08:40 +0000 |
| Subject: | note 83478 added to function.floor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139875@lists.php.net to get a copy of this message | ||
I believe this behavior of the floor function was intended. Note that it says "the next lowest
integer". -1 is "higher" than -1.6. As in, -1 is logically greater than -1.6. To
go lower the floor function would go to -2 which is logically less than -1.6.
Floor isn't trying to give you the number closest to zero, it's giving you the lowest
bounding integer of a float.
In reply to Glen who commented:
Glen
01-Dec-2007 04:22
<?php
echo floor(1.6); // will output "1"
echo floor(-1.6); // will output "-2"
?>
instead use intval (seems to work v5.1.6):
<?php
echo intval(1.6); // will output "1"
echo intval(-1.6); // will output "-1"
?>
----
Server IP: 216.235.15.211
Probable Submitter: 205.178.191.132
----
Manual Page -- http://www.php.net/manual/en/function.floor.php
Edit -- https://master.php.net/note/edit/83478
Del: integrated -- https://master.php.net/note/delete/83478/integrated
Del: useless -- https://master.php.net/note/delete/83478/useless
Del: bad code -- https://master.php.net/note/delete/83478/bad+code
Del: spam -- https://master.php.net/note/delete/83478/spam
Del: non-english -- https://master.php.net/note/delete/83478/non-english
Del: in docs -- https://master.php.net/note/delete/83478/in+docs
Del: other reasons-- https://master.php.net/note/delete/83478
Reject -- https://master.php.net/note/reject/83478
Search -- https://master.php.net/manage/user-notes.php