[Python-ideas] Python Numbers as Human Concept Decimal System

Stefan Krah stefan at bytereef.org
Fri Mar 7 09:11:44 CET 2014


Mark H. Harris <harrismh777 at gmail.com> wrote:
>    You can't be serious.  You have not commented yet...  are you happy with
> this:
> 
>  >>> from decimal import Decimal
> >>> a=Decimal(1)
> >>> b=Decimal(.1)
> >>> a+b
> Decimal('1.100000000000000005551115123')      <==== does this not bother you at
> all ?


You can set a trap:

>>> getcontext().traps[FloatOperation] = True
>>> b = Decimal(.1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
decimal.FloatOperation: [<class 'decimal.FloatOperation'>]
>>> 


Stefan Krah





More information about the Python-ideas mailing list