fuwath

Here's what I'm trying to acheive. I need to have a condition in an if statement so that it occurs only if the value is divisible by 100. Here's a code snippet of what I'm working with:

if (value < 1200 && " ")
{
_departmentID = value;
_rules.MaintainRule("department", false);
PropertyColors["department"] = Color.Black;
}

The condition will be going in place of the quotes. I know it has something to do with % operator but cannot figure out what I need to do. The reasoning is that I only want the if statement to be true if the departmentID is less than 1200 and divisible by 100.



Re: Visual C# Language % Operator

Alberto Poblacion

if (value < 1200 && (_departmentID % 100) == 0) ...

It is called "modulus operator", and it gives you the remainder of the division of the first argument by the second argument. The departmentID is divisible by 100 if the remainder of the division is zero.





Re: Visual C# Language % Operator

fuwath

Ok I think that worked. Just so I understand how it works, the value after the == will be the remainder of _departmentID%100
Say I were to do (_departmentID % 10) == 7, the remainder of the operation would have to be 7 correct





Re: Visual C# Language % Operator

Jeris

yes.

By the way, I think '%' operator is foudamental to any language. you be better consolidate your programming basis.