Scratch that other one, came up with something quite a bit better for speed
on large numbers:

// Obviously only works with intergers (can be fixed but don't need to for
my application)
// Obviously only works where $input > $divisor

function alt_floor ( $input , $divisor ) {

    if ( $input % $divisor == 0 ) {
        return $input;
    }
    
    else {
        for ( $i = $input ; $i % $divisor != 0 ; $i-- ) {}
        
        $i;
        return $i;
    }
}



---------------------
John Asendorf - [EMAIL PROTECTED]
Web Applications Developer
http://www.lcounty.com - NEW FEATURES ADDED DAILY!
Licking County, Ohio, USA
740-349-3631
Nullum magnum ingenium sine mixtura dementiae fuit


> -----Original Message-----
> From: Asendorf, John [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 28, 2003 2:53 PM
> To: Php-Windows (E-mail)
> Subject: [PHP-WIN] Looking for something like floor() only to 
> round to a
> nearest div isor
> 
> 
> I'm looking for a function like floor() only I want it 
> rounded to a number
> that is divisible by another number.  For instance, if the 
> divisor is 6,
> alt_floor ( 15 , 6 ) would yield 12 where 15 is the input and 6 is the
> divisor.  Or, alt_floor ( 174 , 20 ) would yield 160...
> 
> Anyone already do something like this?
> 
> Thanks,  John
> 
> ---------------------
> John Asendorf - [EMAIL PROTECTED]
> Web Applications Developer
> http://www.lcounty.com - NEW FEATURES ADDED DAILY!
> Licking County, Ohio, USA
> 740-349-3631
> Nullum magnum ingenium sine mixtura dementiae fuit
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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

Reply via email to