[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Mauricio de Alencar
Mauricio de Alencar added the comment: Thank you. This function accomplishes what I need, avoiding the float->string->Decimal conversion path. I will use a slight variation of it accepting floats and a precision value: from decimal import Decimal, Contextdef sigdec(f, prec):x = Context(prec

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Stefan Krah
Stefan Krah added the comment: Mauricio de Alencar wrote: > The floats I posted are examples of computation results. The meaningful > figures are related to the precision of the measurements fed to the > computation. Thank you, that makes it clear. Constructing Decimal('256.2') preserves the e

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Mauricio de Alencar
Mauricio de Alencar added the comment: > You need to stop lecturing. I'm sorry, I didn't mean to offend anyone. I just felt I was failing to communicate the issue when I got the suggestion to use format(Decimal(1), ".2f"). > The above sentence you wrote directly contradicts the Wikipedia link

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Stefan Krah
Stefan Krah added the comment: Mauricio de Alencar wrote: > > Mauricio de Alencar added the comment: > > "Digits after the decimal mark" is not the same as "significant digits". > See https://en.wikipedia.org/wiki/Significant_figures > > If I have a list of numbers [256.2, 1.3, 0.5] that have

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Mauricio de Alencar
Mauricio de Alencar added the comment: "Digits after the decimal mark" is not the same as "significant digits". See https://en.wikipedia.org/wiki/Significant_figures If I have a list of numbers [256.2, 1.3, 0.5] that have 3 significant digits each, I would like to have them displayed as: ['256'

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Stefan Krah
Stefan Krah added the comment: Mauricio de Alencar wrote: > String formatting is completely unaware of the concept of *significant > digits*. >>> format(Decimal(1), ".2f") '1.00' -- ___ Python tracker __

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Mauricio de Alencar
Mauricio de Alencar added the comment: String formatting is completely unaware of the concept of *significant digits*. The only format that can get it right for every case is the 'e'. But then you always get the exponent, which is undesirable. I was hopeful that the decimal module would handle

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Mark Dickinson
Changes by Mark Dickinson : -- title: Context setting to print Decimal with as many digits as the "prec" setting -> Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark ___ Python tracker

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Mark Dickinson
Mark Dickinson added the comment: > Therefore, if I request 2 digits of precision, I expect 2 digits in the > output. The `prec` attribute in the context refers to the total number of *significant digits* that are storable, and not to the number of digits after the decimal point. `Decimal` i

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Mauricio de Alencar
Mauricio de Alencar added the comment: According to the docs (http://docs.python.org/3/library/decimal.html): "The decimal module incorporates a notion of significant places so that 1.30 + 1.20 is 2.50. The trailing zero is kept to indicate significance. This is the customary presentation for

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-04 Thread Mark Dickinson
Mark Dickinson added the comment: The output is correct, though the tiny precision makes it look strange. The decimal module is following the usual rules for 'ideal' exponents: - For *exactly representable* results, the ideal exponent is 0, and the output will be chosen to have exponent as cl

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-03 Thread Berker Peksag
Changes by Berker Peksag : -- nosy: +mark.dickinson, skrah ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http

[issue20502] Context.create_decimal_from_float() inconsistent precision for zeros after decimal mark

2014-02-03 Thread Mauricio de Alencar
New submission from Mauricio de Alencar: The following code demonstrates an inconsistency of this method in dealing with zeros after the decimal mark. from decimal import Context context = Context(prec=2) for x in [100., 10., 1., 0.1]: print(context.create_decimal_from_float(x), context