Thread: rounding?

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    18
    Rep Power
    0

    rounding?


    Can you round a number in python, like you do in elementary school?

    I've searched and didn't see anything but maybe I just didn't look hard enough..
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You're looking for the built in round() function, from the docs:

    Code:
    round( x[, n])
    
    Return the floating point value x rounded to n digits after the
    decimal point. If n is omitted, it defaults to zero. The result
    is a floating point number. Values are rounded to the closest
    multiple of 10 to the power minus n; if two multiples are
    equally close, rounding is done away from 0 (so. for example,
    round(0.5) is 1.0 and round(-0.5) is -1.0).
    I would give you a better example however i dont have access to Python right now sorry .

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    18
    Rep Power
    0
    Ahah, that is it. Thanks!

    I just have to play around with that a little bit..

IMN logo majestic logo threadwatch logo seochat tools logo