Message239504
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 :) |
|
| Date |
User |
Action |
Args |
| 2015-03-29 17:40:47 | scoder | set | recipients:
+ scoder, rhettinger, mark.dickinson, eric.smith, ezio.melotti, skrah, martin.panter, serhiy.storchaka, wolma, tuomas.suutari |
| 2015-03-29 17:40:47 | scoder | set | messageid: <[email protected]> |
| 2015-03-29 17:40:47 | scoder | link | issue23602 messages |
| 2015-03-29 17:40:47 | scoder | create | |
|