Thread: float numbers

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    41

    float numbers

    im making a prime number generator and i need to test to see if a float variable has numbers after a decimal, how would i do this?

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Code:
    if (floor(number) != number)
       // digits after the decimal
    else
       // no digits after the decimal

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Code:
    float f = 1.5;
    if (f == (float)((int)f))
       //has not fractional part
    Remember that floor(-2.8) == 3.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rounding numbers
    By maple23 in forum C Programming
    Replies: 3
    Last Post: 05-26-2008, 12:33 AM
  2. pin number question
    By melee in forum C Programming
    Replies: 19
    Last Post: 12-11-2004, 01:39 PM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  4. menu problems with functions
    By Spectrum48k in forum C Programming
    Replies: 3
    Last Post: 07-20-2002, 04:53 PM
  5. Need more eyes to find problem??
    By sailci in forum C++ Programming
    Replies: 2
    Last Post: 03-24-2002, 10:03 PM