Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Rounding a number to nearest even
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Graham Breed, post: 3534209"] If you care about such details, you may be better off using decimals instead of floats. import decimal decimal.Decimal("1.5").to_integral( rounding=decimal.ROUND_HALF_EVEN) decimal.Decimal("2.5").to_integral( rounding=decimal.ROUND_HALF_EVEN) ROUND_HALF_EVEN is the default, but maybe that can be changed, so explicit is safest. If you really insist, import decimal def my_round(f): d = decimal.Decimal(str(f)) rounded = d.to_integral(rounding=decimal.ROUND_HALF_EVEN) return int(rounded) Graham [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Rounding a number to nearest even
Top