[issue45918] Possibly use ROUND_05UP in decimal's localcontext() example

Raymond Hettinger report at bugs.python.org
Sun Nov 28 13:05:23 EST 2021


New submission from Raymond Hettinger <raymond.hettinger at 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 <report at bugs.python.org>
<https://bugs.python.org/issue45918>
_______________________________________


More information about the Python-bugs-list mailing list