[issue23602] Implement __format__ for Fraction

Stefan Behnel report at bugs.python.org
Sun Mar 29 19:40:47 CEST 2015


Stefan Behnel added the comment:

Or, speaking of "division with remainder":

    n, r = divmod(nom * 10**prec, den)
    if r * 5 >= den:
        n += 1
    x = str(n)
    print('%s.%s' % (x[:-prec], x[-prec:]))

... minus the usual off-by-one that the tests would quickly find :)

----------

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


More information about the Python-bugs-list mailing list