The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
![]()
How can I check if an integer is an even number?
I want to have a submit button and for each of the users that clicks it, it adds their usernames to a field in a table. However, I cannot have the # of users to be an uneven number (IE 1, 3, 5, 7 etc). So there is my problem. Anyone? |
#2
|
|||
|
|||
![]()
I'm sure there are prolly cleaner ways to write this, but....
Code:
if($value % 2 == 0) { // it's even }else{ $value += 1; // or whatever } |
#3
|
||||
|
||||
![]()
you could do something like this... if you don't find a better way
![]() if (($number/2) == (intval(($number+1)/2)) { //is even number } else { //is uneven number } |
#4
|
||||
|
||||
![]()
Cheers people
![]() I tried both of them first with a single figured number, and they both worked fine. I then tried with 20000000000000000000 just for the hell of it. Colins code said this was uneven, while Tektons said even. Then I tried with 20000000000000000001 which reversedly Colins code called uneven, while Tektons called it even. ![]() Now I dont need such a high number, just 100 or so. And they both say thats even XD Thanks again guys ![]() |
#5
|
|||
|
|||
![]() Quote:
PHP Code:
|
#6
|
||||
|
||||
![]()
Also it's always nice to write a function for these things
![]() PHP Code:
PHP Code:
|
#7
|
||||
|
||||
![]()
Added the fucntion for future usage
![]() But I feel pretty sure that the arguement in the function ($num in above) and the function coding ($number in above) should be equal ![]() |
#8
|
||||
|
||||
![]()
Yep you're write, I've been programming all day so that's my excuse
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|