Raymond Hettinger <rhettin...@users.sourceforge.net> added the comment:
The decimal constructor should be lossless. The underlying spec was designed with the notion that all numbers in decimal are exact; operations can be lossy but the numbers themselves are exact. Accordingly, I recommend Decimal.from_float(f) with no qualifiers or optional arguments. To support the use case of wanting to round the input, I suggest a separate method modeled on Context.create_decimal(). It can either be an extension of the existing method or a new method like Context.create_decimal_from_float(). I recommend the former since rounding is already implied by the context qualifier. Either way, the effect would be the same as Decimal.from_float(f) + 0 in a given context. Per the docs: "Creates a new Decimal instance from num but using self as context. Unlike the Decimal constructor, the context precision, rounding method, flags, and traps are applied to the conversion." _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue4796> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com