Re: round a number down to an odd number

From: Date: Sun, 10 Dec 2000 19:52:57 +0000
Subject: Re: round a number down to an odd number
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-29577@lists.php.net to get a copy of this message
"Tom Beidler" <tbeidler@mindspring.com> wrote: > I have a page where I'm trying to swap out images to represent a product. > There's one image for every 2 products id's. Is there a way in PHP to return > an odd number? That way I can name the images after the odd part numbers, if > someone orders the small size which would have the even part number, I could > have the formula knock off a number, and use the odd part number image. If > they would order the large the formula wouldn't knock off a number. Use the modulus operator "%" which returns a remainder. if( $num % 2 == 0 ) // $num is an even number { $num = $num - 1; } -- Steve Werby COO 24-7 Computer Services, LLC Tel: 804.817.2470 http://www.247computing.com/

« previous php.general (#29577) next »