gilgalbiblewhee

07-23-2008, 02:05 AM

I need to express:

if($i!=){

$i shouldn't be a multiple of 10.

if($i!=){

$i shouldn't be a multiple of 10.

View Full Version : how to avoid multiples of 10?

gilgalbiblewhee

07-23-2008, 02:05 AM

I need to express:

if($i!=){

$i shouldn't be a multiple of 10.

if($i!=){

$i shouldn't be a multiple of 10.

oesxyl

07-23-2008, 02:07 AM

I need to express:

if($i!=){

$i shouldn't be a multiple of 10.

if($i % 10 != 0){

regards

if($i!=){

$i shouldn't be a multiple of 10.

if($i % 10 != 0){

regards

p4plus2

07-23-2008, 04:23 AM

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

<?php

function isdiv($number, $divby){

if($number % $divby == 0){

return true;

}

else{

return false;

}

}

?>

useable for more than one number more than once.....

To use simple

$numb = isdiv(10, 2);

that will set $numb to true.

<?php

function isdiv($number, $divby){

if($number % $divby == 0){

return true;

}

else{

return false;

}

}

?>

useable for more than one number more than once.....

To use simple

$numb = isdiv(10, 2);

that will set $numb to true.

Len Whistler

07-23-2008, 06:49 AM

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.

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

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.

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

Fou-Lu

07-23-2008, 07:40 AM

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

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

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.