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

This is a discussion on How to get the fraction part of a float as an integer? within the C++ Programming forums, part of the General Programming Boards category; I wonder how I can get the fraction part of a float number. For example, I want to get the ...

  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,825
    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, 01:19 AM
  4. Possible Loss of data
    By silicon in forum C Programming
    Replies: 3
    Last Post: 03-24-2004, 11:25 AM
  5. error declaration terminated incorrectly help
    By belfour in forum C++ Programming
    Replies: 7
    Last Post: 11-25-2002, 08:07 PM

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