note 127306 added to function.round

From: Date: Tue, 19 Jul 2022 17:43:14 +0000
Subject: note 127306 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-219037@lists.php.net to get a copy of this message
A simple way to always round a float to the next integer. <?php function RoundNextInt(float $num) { $r = round($num, 0, PHP_ROUND_HALF_UP); return ($r < $num)?($r+1):$r; } ?> Test: <?php $c = 0; do { $num = rand(1, 1000)/7; echo $num.": ".RoundNextInt($num).PHP_EOL; $c++; } while($c < 100); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 181.231.25.23) ---- Manual Page -- https://php.net/manual/en/function.round.php Edit -- https://main.php.net/note/edit/127306 Del: integrated -- https://main.php.net/note/delete/127306/integrated Del: useless -- https://main.php.net/note/delete/127306/useless Del: bad code -- https://main.php.net/note/delete/127306/bad+code Del: spam -- https://main.php.net/note/delete/127306/spam Del: non-english -- https://main.php.net/note/delete/127306/non-english Del: in docs -- https://main.php.net/note/delete/127306/in+docs Del: other reasons-- https://main.php.net/note/delete/127306 Reject -- https://main.php.net/note/reject/127306 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219037) next »