C problem for rounding a decimal value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zenoba
    New Member
    • Oct 2008
    • 8

    C problem for rounding a decimal value

    i have written a code which yields a decimal value for example 7.23, but i need the value greater than this number i.e the number integer 8.
    Can anyone suggest a way to do this please?
    what should I use?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Look at the functions in math.h

    Comment

    • curiously enough
      New Member
      • Aug 2008
      • 79

      #3
      If you have the float number a, just write: (int)a+1 and you'll have the rounded number you want(and use the condition that a>(int)a)

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by curiously enough
        If you have the float number a, just write: (int)a+1 and you'll have the rounded number you want(and use the condition that a>(int)a)
        Don't do that: an int isn't large enough to hold the integer part of any double value.
        Better use the ceil() function (in <math.h>).

        kind regards,

        Jos

        Comment

        • Zenoba
          New Member
          • Oct 2008
          • 8

          #5
          Originally posted by JosAH
          Don't do that: an int isn't large enough to hold the integer part of any double value.
          Better use the ceil() function (in <math.h>).

          kind regards,

          Jos
          thanks Jos
          that solved my problem

          Comment

          Working...