[Python-ideas] Deprecate the round builtin
Steven D'Aprano
steve at pearwood.info
Mon Oct 1 03:44:36 CEST 2012
On Sun, Sep 30, 2012 at 02:38:33PM -0700, Gregory P. Smith wrote:
> Why suggest adding new round-like functions to the math module rather than
> defining a new round method on all numerical objects?
round already calls the special __round__ method, and in 3.2 works with
ints, floats, Decimals and Fractions. Only complex misses out.
py> round(12345, -2)
12300
py> from decimal import Decimal as D
py> round(D("1.2345"), 2)
Decimal('1.23')
py> from fractions import Fraction as F
py> round(F(12345, 10000), 2)
Fraction(123, 100)
--
Steven
More information about the Python-ideas
mailing list