Alternative to % int division

This is a discussion on Alternative to % int division within the C++ Programming forums, part of the General Programming Boards category; Does anyone know of a easy way to separate or display numbers to the left of the decimal point like ...

  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,386
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    The modf function in math.h does just that

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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
    561
    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, 02:51 AM
  3. problem with sorting
    By pinkpenguin in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 10: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, 04:26 PM

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