By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,332 Members | 1,083 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,332 IT Pros & Developers. It's quick & easy.

Re: Where is the correct round() method? Use math.ceil

P: n/a
Le Monday 28 July 2008 02:35:08 Herman, vous avez écrit*:
Where is the correct round() method?
Hello,

I need a round function that _always_ rounds to the higher integer if
the argument is equidistant between two integers. In Python 3.0, this
is not the advertised behavior of the built-in function round() as

seen below:
>>round(0.5)

0
>>round(1.5)

2
>>round(2.5)

2
Hmm, I don't have the same result in python2.6, I suspect it's a floating
point precision problem, try just to type "0.5" in the console to see the
exact representation of this value on your system, it may be just over or
just down by a small quantity.

On mine with 2.6 this typically give :
>>>[26]: 0.5
...[26]: 0.5
>>>[27]: 0.49
...[27]: 0.48999999999999999
>>>[29]: 0.51
...[29]: 0.51000000000000001
>>>[28]: 1.1
...[28]: 1.1000000000000001
>>>[35]: round(0.5)
...[35]: 1.0
--
_____________

Maric Michaud
Jul 28 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.