Check if number is divisible by 24 [closed]

Use the Modulus operator:

if (number % 24 == 0)
{
   ...
}

The % operator computes the remainder after dividing its first operand
by its second. All numeric types have predefined remainder operators.

Pretty much it returns the remainder of a division: 25 % 24 = 1 because 25 fits in 24 once, and you have 1 left. When the number fits perfectly you will get a 0 returned, and in your example that is how you know if a number is divisible by 24, otherwise the returned value will be greater than 0.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)