Skip to content

Instantly share code, notes, and snippets.

@drincruz
Created September 14, 2014 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drincruz/3db79bdb145a34dc0ab1 to your computer and use it in GitHub Desktop.
Save drincruz/3db79bdb145a34dc0ab1 to your computer and use it in GitHub Desktop.
Python 2 round() vs. Python 3 round()
>>> round(0.5)
1.0
>>> round(2.5)
3.0
>>> round(0.4)
0.0
>>> round(2.6)
3.0
>>> round(0.5)
0
>>> round(2.5)
2
>>> round(0.4)
0
>>> round(2.6)
3
@drincruz
Copy link
Author

From Python 3 docs:

For the built-in types supporting round(), values are rounded to the closest multiple of 10 to
the power minus ndigits; if two multiples are equally close, rounding is done toward the even
choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). The
return value is an integer if called with one argument, otherwise of the same type as
number.

https://docs.python.org/3/library/functions.html#round

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment