Thread: Alternative to % int division

  1. #1
    Unregistered
    Guest

    Alternative to % int division

    Does anyone know of a easy way to separate or display numbers to the left of the decimal point

    like separate: 10.5

    into 10 and 5?

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Uhm. Well, I think that

    x = 10.5;

    a = (int) x; /* = 10 */

    y = (int)(x * 10.0); /* = 105 */
    z = y - 10 * a; /* = 5 */

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The modf function in math.h does just that

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I realize this is a dumb comment, but does anyone else think that the % in the subject line looks like a 96?

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Yeah, I see it now.

  6. #6
    Unregistered
    Guest
    Originally posted by Salem
    The modf function in math.h does just that
    Awesome, thanks! Thats EXACTLY what I was looking for, I can't believe I didn't browse the function appendix!

  7. #7
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    Yeah % does look like 96 if you stare at it. I've never noticed that before.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 10:28 PM
  2. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  3. problem with sorting
    By pinkpenguin in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 11:06 AM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM