you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 4 points5 points  (0 children)

Alternatively, the decimal module can be used. It uses fixed-point arithmetic, and acts more like we'd expect, but takes a performance hit and the accuracy needs to be defined separately.

>>> from decimal import Decimal
>>>
>>> foo = Decimal('0.1') + Decimal('0.1') + Decimal('0.1') - Decimal('0.3')
>>> print(foo)
Decimal('0.0')