note 89348 added to function.floor
| From: | elarattriggerdotee at osu1 dot php dot net | Date: | Wed, 04 Mar 2009 11:44:13 +0000 |
| Subject: | note 89348 added to function.floor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151441@lists.php.net to get a copy of this message | ||
<?php
$no1 = 930;
$no2 = 18.6;
$result = $no1 / $no2;
var_dump($result); // float(50)
// BUT!
floor($result); // float(49)
?>
"Returns the next lowest integer value by rounding down value if necessary."
Maybe 930 / 18.6 is something like 49.99999999999999999999999999999. In that case floor function
works correctly and result is 49.
(See "jay at w3prodigy dot com" post on 25-Mar-2008 10:01)
But this is not that value what i expect.
Solution for me is round this value with reasonable precision, for example 10
<?php
floor(round($result, 10)); // float(50)
// note
floor(round($result, 14)); // float(50)
floor(round($result, 15)); // float(49)
?>
Tested on:
PHP/5.2.5 Apache/2.2.3 (Linux/SUSE)
PHP/5.1.6 Apache/2.0.59 (Win32)
PHP/5.1.6 Apache/2.0.61 (Unix)
----
Server IP: 212.47.220.13
Probable Submitter: 89.219.158.37
----
Manual Page -- http://www.php.net/manual/en/function.floor.php
Edit -- https://master.php.net/note/edit/89348
Del: integrated -- https://master.php.net/note/delete/89348/integrated
Del: useless -- https://master.php.net/note/delete/89348/useless
Del: bad code -- https://master.php.net/note/delete/89348/bad+code
Del: spam -- https://master.php.net/note/delete/89348/spam
Del: non-english -- https://master.php.net/note/delete/89348/non-english
Del: in docs -- https://master.php.net/note/delete/89348/in+docs
Del: other reasons-- https://master.php.net/note/delete/89348
Reject -- https://master.php.net/note/reject/89348
Search -- https://master.php.net/manage/user-notes.php