Re: Rounding down?

From: Date: Sat, 22 Aug 2009 16:45:37 +0000
Subject: Re: Rounding down?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-297084@lists.php.net to get a copy of this message
Hi, > ... A little modification: <?php /** * Rounds down to the nearest 50 */ function myRound($val) { $units = intval(substr($val, -2)); return intval(substr($val, 0, -2) . ($units >= 50 ? '50' : '00')); } echo myRound(449) . '<br />'; // 400 echo myRound(450) . '<br />'; // 450 echo myRound(356) . '<br />'; // 350 echo myRound(79) . '<br />'; // 50 ?> PS I haven't checked if there's a PHP function for this. -- Richard Heyes HTML5 graphing: RGraph - www.rgraph.net (updated 8th August) Lots of PHP and Javascript code - http://www.phpguru.org

« previous php.general (#297084) next »