[issue3024] Integer conversion inconsistent

Raymond Hettinger report at bugs.python.org
Mon Jun 2 00:51:36 CEST 2008


Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

This is exactly what int() is supposed to do.  For other kinds of 
rounding, look at round(), math.floor(), math.ceil(), and many rounding 
options in the decimal module:

from decimal import Decimal
>>> Decimal('-23.15').to_integral(ROUND_FLOOR)
Decimal("-24")
>>> Decimal('-23.15').to_integral(ROUND_CEILING)
Decimal("-23")
>>> Decimal('-23.15').to_integral(ROUND_DOWN)
Decimal("-23")
>>> Decimal('-23.15').to_integral(ROUND_HALF_EVEN)
Decimal("-23")

----------
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3024>
_______________________________________


More information about the Python-bugs-list mailing list