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
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
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` is
Changes by Mark Dickinson dicki...@gmail.com:
--
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
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
Stefan Krah added the comment:
Mauricio de Alencar rep...@bugs.python.org wrote:
String formatting is completely unaware of the concept of *significant
digits*.
format(Decimal(1), .2f)
'1.00'
--
___
Python tracker rep...@bugs.python.org
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',
Stefan Krah added the comment:
Mauricio de Alencar rep...@bugs.python.org 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,
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 you
Stefan Krah added the comment:
Mauricio de Alencar rep...@bugs.python.org 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
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 =
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),
Changes by Berker Peksag berker.pek...@gmail.com:
--
nosy: +mark.dickinson, skrah
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20502
___
___
13 matches
Mail list logo