note 102848 added to function.floor
| From: | JoeT dot at osu1 dot php dot net | Date: | Thu, 10 Mar 2011 06:49:57 +0000 |
| Subject: | note 102848 added to function.floor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177730@lists.php.net to get a copy of this message | ||
Yet another answer: why make a second function call when you can use basic math operators (or is
that what operators secretly do)?
function floor_x($number, $x){
return $number - $number % $x;
}
floor_x(250, 100);
// 200
floor_x(23, 20);
// 20
floor_x(32, 100);
// 0
The modulus gives you the remainder to subtract from the original number. In ex.1, the remainder is
50. In ex.2, it's 3. And in ex.4 it's 32 because 32 / 100 = 0, rem 32.
----
Server IP: 69.147.83.197
Probable Submitter: 76.235.204.165
----
Manual Page -- http://www.php.net/manual/en/function.floor.php
Edit -- https://master.php.net/note/edit/102848
Del: integrated -- https://master.php.net/note/delete/102848/integrated
Del: useless -- https://master.php.net/note/delete/102848/useless
Del: bad code -- https://master.php.net/note/delete/102848/bad+code
Del: spam -- https://master.php.net/note/delete/102848/spam
Del: non-english -- https://master.php.net/note/delete/102848/non-english
Del: in docs -- https://master.php.net/note/delete/102848/in+docs
Del: other reasons-- https://master.php.net/note/delete/102848
Reject -- https://master.php.net/note/reject/102848
Search -- https://master.php.net/manage/user-notes.php