Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    183
    Thanks
    17
    Thanked 0 Times in 0 Posts

    How to check to see if a number is divisable by 1000

    HI

    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?


    Thanks

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    PHP Code:
    <?php

    $divisible 
    = ( $num 1000 == );

    if ( 
    $divisible )
        echo 
    'exactly divisible by 1000';
    else
        echo 
    'not exactly divisible by 1000, we have a remainder';

    ?>
    Last edited by kbluhm; 06-20-2007 at 05:30 AM.

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Or by using a ternary operator
    PHP Code:
    $divisible = ($num 1000 == 0) ? 'exactly divisible by 1000' 'not exactly divisible by 1000, we have a remainder';
    echo 
    $divisible
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    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.
    Last edited by kbluhm; 06-20-2007 at 06:06 AM.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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