Thread: checking for whole number

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    33

    checking for whole number

    is there a way to check to see if a number is whole?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You can check a floating point number to see if it is whole like this:

    #include <math.h>
    .
    .
    double d = 3.0000001;

    if (floor(d) == d)
    cout << "Number is a whole number.\n";

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    whole number issue

    many times floating points will not evaluate to whole numbers
    because of a lingering supersmall fraction... instead you check for a range of accuracy....


    float flA = 3.0;
    int iA = (int)3.0;

    if( (flA - iA) > .001 ) ......
    zMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  2. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  3. checking for floating point number
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 08:14 PM
  4. Perfect number...
    By Argo_Jeude in forum C++ Programming
    Replies: 8
    Last Post: 07-12-2005, 01:53 PM
  5. [C++/WinAPI] Checking number of allocated memory
    By jagi in forum C++ Programming
    Replies: 2
    Last Post: 03-28-2005, 06:10 PM