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 Decimal('256.2') preserves the exact value, regardless of the context precision. All arithmetic functions accept arbitrary precision input and use all digits regardless of the context precision. To put it differently, decimal refuses to guess and treats any input as having the correct number of significant digits. If you want to attribute a significance to a series of input numbers, I guess you have to do it manually, using something like: def mk_full_coeff(x): prec = getcontext().prec adj = x.adjusted() if adj >= prec: return +x else: return x.quantize(Decimal(1).scaleb(adj-prec+1)) >>> c = getcontext() >>> c.prec = 3 >>> [mk_full_coeff(x) for x in [Decimal('256.2'), Decimal('1.3'), >>> Decimal('0.5')]] [Decimal('256'), Decimal('1.30'), Decimal('0.500')] ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20502> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com