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

2014-02-04 Thread Mark Dickinson

Changes by Mark Dickinson :


--
type: enhancement -> behavior
versions: +Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2014-02-04 Thread Mark Dickinson

Mark Dickinson added the comment:

If you're after a particular string representation, you'll probably find that 
string formatting meets your needs.

Python 3.3.3 (default, Nov 24 2013, 14:34:37) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal
>>> x = Decimal('3.3')
>>> x
Decimal('3.3')
>>> "{:.4f}".format(x)  # string representation with 4 digits after the point.
'3.3000'

Reclosing this issue.  If you want to pursue your proposal, please open a 
separate issue for that rather than reopening this one.  Thanks!

--
resolution:  -> invalid
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2014-02-04 Thread Mauricio de Alencar

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com