View Full Version : How to check to see if a number is divisable by 1000
06-20-2007, 04:57 AM
Does anyone know how to check to see if a number is divisible by 1000 like for example if the num being checked is 2000 it is true or 1 and if its 2001 its false or 0
Any one know how to do this?
06-20-2007, 05:06 AM
$divisible = ( $num % 1000 == 0 );
if ( $divisible )
echo 'exactly divisible by 1000';
echo 'not exactly divisible by 1000, we have a remainder';
06-20-2007, 05:52 AM
Or by using a ternary operator
$divisible = ($num % 1000 == 0) ? 'exactly divisible by 1000' : 'not exactly divisible by 1000, we have a remainder';
06-20-2007, 06:03 AM
While that is true, the if-else in my example was intended to demonstrate the boolean result... answering the query of the intended result and not the display text. Besides, swapping an if-else for a ternary operator is fairly redundant when giving examples. You've posted an identical solution. :thumbsup:
06-20-2007, 07:22 AM
Yes I know I posted an identical solution. I was just posting a shorter method. The key part to the solutions given is the modulus operator. It divides one number into another and leaves a remainder. If the remainder is greater than 0 then the two numbers aren't divisible by each other.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.