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 <[email protected]>
<http://bugs.python.org/issue23602>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com