Thread: How to get the fraction part of a float as an integer?

  1. #1
    A. Motaz
    Guest

    Question How to get the fraction part of a float as an integer?

    I wonder how I can get the fraction part of a float number. For example, I want to get the integer 75 of the float 56.75. Something like,
    frac(56.75) = 75

    Thanks in advance.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Here's a rather hackish way....
    Code:
    int frac(double a)
    {
       int b;
       b = floor(a);
       b = (a-b) * 100;
       return b;
    }
    That should work for numbers with 2 after the decimal point....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Integer to 32-bit Float?
    By papagaio in forum C Programming
    Replies: 8
    Last Post: 09-09-2008, 08:35 PM
  2. modifying help plz ( int to float )
    By sh4k3 in forum C Programming
    Replies: 11
    Last Post: 06-29-2007, 06:46 AM
  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. Possible Loss of data
    By silicon in forum C Programming
    Replies: 3
    Last Post: 03-24-2004, 12:25 PM
  5. error declaration terminated incorrectly help
    By belfour in forum C++ Programming
    Replies: 7
    Last Post: 11-25-2002, 09:07 PM