[issue20502] Context setting to print Decimal with as many digits as the "prec" setting

Mauricio de Alencar report at bugs.python.org
Tue Feb 4 14:10:36 CET 2014


Mauricio de Alencar added the comment:

I propose then to create a context setting that switches between the current textual representation of a Decimal and one that is "right zeros padded" up to context precision.

Such that the line:

print(Context(prec=4, precise_repr=True).create_decimal_from_float(1.))

would output "1.000" 



I post bellow a workaround for getting the result I expect just in case there is anybody else with similar expectations.


from decimal import Context

def dec(num, prec):
    return Context(prec=prec).create_decimal('{{:.{:d}e}}'.format(prec - 1).format(num))



Thanks for you attention.

----------
resolution: invalid -> 
status: closed -> open
title: Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark -> Context setting to print Decimal with as many digits as the "prec" setting
type: behavior -> enhancement
versions:  -Python 3.3

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


More information about the Python-bugs-list mailing list