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="bdsatish, post: 3534177"] No. not at all. The clause "nearest even" comes into picture only when a number is of form "x.5" or else it's same as builtin round( ). new_round(3.0) must be 3.0 itself. Here is the mathematical definition of what I want: If 'n' is an integer, new_round(n+0.5) = n if n/2 is integer new_round(n+0.5) = (n+1) if (n+1)/2 is integer In all other cases, new_round() behave similarly as round( ). Here are the results I expect: new_round(3.2) = 3 new_round(3.6) = 4 new_round(3.5) = 4 new_round(2.5) = 2 new_round(-0.5) = 0.0 new_round(-1.5) = -2.0 new_round(-1.3) = -1.0 new_round(-1.8) = -2 new_round(-2.5) = -2.0 The built-in function doesnt meet my needs for round(-2.5) or round(2.5) [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Rounding a number to nearest even
Top