[Python-ideas] float vs decimal
wilk at flibuste.net
Thu Mar 12 13:25:36 CET 2009
On 11-03-2009, Chris Rebert wrote:
> It's in the FAQ section of the decimal module -
> http://docs.python.org/library/decimal.html :
> 17. Is there a way to convert a regular float to a Decimal?
> A. Yes, all binary floating point numbers can be exactly expressed as
> a Decimal. An exact conversion may take more precision than intuition
> would suggest, so we trap Inexact to signal a need for more precision:
> def float_to_decimal(f):
> [definition snipped]
> 17. Why isn’t the float_to_decimal() routine included in the module?
> A. There is some question about whether it is advisable to mix binary
> and decimal floating point. Also, its use requires some care to avoid
> the representation issues associated with binary floating point:
I understand. It means that explicit is better and that we should know
what we do with decimal numbers...
William Dodé - http://flibuste.net
More information about the Python-ideas