Daniel Keast

Python Decimal

programming, python

The Decimal class in the standard library is the way to avoid double precision errors in Python.

>>>> 0.1 + 0.2
0.30000000000000004
>>> from decimal import Decimal
>>> Decimal('0.1') + Decimal('0.2')
Decimal('0.3')