note 98918 modified in function.round by googleguy

From: Date: Sun, 09 Dec 2012 08:20:10 +0000
Subject: note 98918 modified in function.round by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192412@lists.php.net to get a copy of this message
Since the mode parameter for options like PHP_ROUND_HALF_UP is available as of PHP 5.3, here is an alternative for ceiling: <?php echo 252 / 40; // 6.3 ?> If I round this: <?php echo round(252 / 40); // 6 ?> You can also use a ceil (which might be useful for pagination): <?php echo ceil(252/40); // 7 ?> [Edited by: googleguy@php.net for clarity] --was-- The PHP_ROUND_HALF_UP is unabled to less php 5.3, but I've a solution for this: <?php echo 252 / 40; // 6.3 ?> If I round this: <?php echo round(252 / 40); // 6 ?> But I like to enable result like PHP_ROUND_HALF_UP. I can do this: <?php echo round((252/40) + 0.5); // 7 ?> It's usefull to paginators ;) http://php.net/manual/en/function.round.php

« previous php.notes (#192412) next »