Thread: C arithmatic dividing question

  1. #1
    Registered User errigour's Avatar
    Join Date
    Mar 2009
    Posts
    102

    C arithmatic dividing question

    Is there a way for me to get a rounded down number from division math.

    I'd like to be able to get a hover position from a division.

    example:
    Code:
    hoverx = roundeddownatallcost(mouse_x / TILESIZE;)

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    what are the data types of hoverx,mouse_x and TILESIZE?

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    I think you want the "floor" function. floor(3) - Linux man page

    Example:
    Code:
    double x = 100., y = 3.;
    double z = floor(x / y);
    Or you can use integer division:
    Code:
    int x = 100, y = 3;
    int z = x/y;
    Note that C rounds the result toward zero, which is different from rounding down only for negative results. If both numbers are always positive then you don't have to worry about this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with interger arithmatic
    By newbc in forum C Programming
    Replies: 11
    Last Post: 03-24-2011, 10:38 AM
  2. Question about data types and basic arithmatic
    By hellogamesmaste in forum C Programming
    Replies: 5
    Last Post: 08-08-2009, 06:51 AM
  3. arithmatic operations without using them..
    By Ajay Bahadur in forum C++ Programming
    Replies: 8
    Last Post: 05-16-2007, 01:33 PM
  4. basic arithmatic
    By voodoo3182 in forum C Programming
    Replies: 3
    Last Post: 08-15-2005, 03:09 PM
  5. ? as a arithmatic operator
    By JeffDVand in forum C Programming
    Replies: 2
    Last Post: 10-14-2002, 08:31 AM