[SOLVED] Change odd number to first highest even number?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

[SOLVED] Change odd number to first highest even number?

Post by tomfra »

I don't know if there is a simple solution but just in case...

I want to get the first highest *even* number for a given odd number.

I.e.: if $odd = 15 I want to get $even = 16 .

Any idea?

Thanks!

Tomas
Last edited by tomfra on Thu Sep 09, 2004 7:04 am, edited 1 time in total.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Code: Select all

if (fmod($odd,2)) $even=$odd+1;
For a better understanding I would recommend you look at fmod, floor and ceil...
http://www.php.net/manual/en/ref.math.php
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

Suberb, thanks!

Tomas
Post Reply