New submission from Raymond Hettinger <raymond.hettin...@gmail.com>:
Candidate example: with localcontext() as ctx: ctx.prec += 10 # Perform a higher precision calculation ctx.rounding = ROUND_05UP # Avoid double rounding of the final calculation step s = calculate_something() s = +s # Round the final result back to the default precision Thoughts: * This would highlight the intended purpose of ROUND_05UP. * Usually, it would slightly improve accuracy. * OTOH, it would rarely make a difference in practice. https://docs.python.org/3/library/decimal.html#decimal.localcontext ---------- assignee: rhettinger components: Documentation messages: 407215 nosy: mark.dickinson, rhettinger, tim.peters priority: normal severity: normal status: open title: Possibly use ROUND_05UP in decimal's localcontext() example versions: Python 3.10, Python 3.11 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45918> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com