Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: how to avoid multiples of 10?

1. ## how to avoid multiples of 10?

I need to express:
PHP Code:
``` if(\$i!=){  ```
\$i shouldn't be a multiple of 10.

• Originally Posted by gilgalbiblewhee
I need to express:
PHP Code:
``` if(\$i!=){  ```
\$i shouldn't be a multiple of 10.
PHP Code:
``` if(\$i % 10 != 0){  ```
regards

• tiny bit more usefull for if you wanna avoid other numbers in the future...

PHP Code:
``` <?phpfunction isdiv(\$number, \$divby){      if(\$number &#37; \$divby == 0){             return true;      }      else{             return false;      }}?> ```
useable for more than one number more than once.....
Edit:
To use simple
\$numb = isdiv(10, 2);
that will set \$numb to true.

• Originally Posted by p4plus2
tiny bit more usefull for if you wanna avoid other numbers in the future...

I think oesxyl solution is the best. Just replace the 10 with any number and when the remainder = 0 it means that you have reached a multiple of that number. I recommend that the OP study the PHP modulus operator (%), it can be used for all sorts of neat things like alternating row colors, switching banner ads, etc.

-------------

• The actual modulus command has some other uses as well, which is why I would also stick with it.
PHP has a built in one called fmod for floating notation. I've never used it, but I figure an int typecast would suffice for it. The user notes claim that 1 % 0.2 results in 0.2, but best I remember from computer mathematics that is technically correct for the binary conversion between them. This is the crap that happens when ints are mixed with floats :P

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•