Re: Rounding down?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux