note 83150 added to function.round

From: Date: Tue, 13 May 2008 02:03:39 +0000
Subject: note 83150 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-139323@lists.php.net to get a copy of this message
If you wish to round a number to the nearest X, here is a simple function: <?php function roundnum ($num, $nearest) { $ret = 0; $mod = $num % $nearest; if ($mod >= 0) $ret = ( $mod > ( $nearest / 2)) ? $num + ( $nearest - $mod) : $num - $mod; else $ret = ( $mod > (-$nearest / 2)) ? $num - $mod : $num + ( -$nearest - $mod); return $ret; } echo roundnum (1234, 15); // round to the nearest 15 echo roundnum (1234, 5); // round to the nearest 5 ?> more info at http://www.markblah.com/2008/05/11/php-round-number-to-nearest-x/ ---- Server IP: 203.88.112.146 Probable Submitter: 203.153.234.45 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/83150 Del: integrated -- https://master.php.net/note/delete/83150/integrated Del: useless -- https://master.php.net/note/delete/83150/useless Del: bad code -- https://master.php.net/note/delete/83150/bad+code Del: spam -- https://master.php.net/note/delete/83150/spam Del: non-english -- https://master.php.net/note/delete/83150/non-english Del: in docs -- https://master.php.net/note/delete/83150/in+docs Del: other reasons-- https://master.php.net/note/delete/83150 Reject -- https://master.php.net/note/reject/83150 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139323) next »