float numbers

This is a discussion on float numbers within the C++ Programming forums, part of the General Programming Boards category; im making a prime number generator and i need to test to see if a float variable has numbers after ...

  1. #1
    PHP
    PHP is offline
    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,676
    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, 12: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, 01: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, 09:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21