Python Decimal

Programming, Python

Floating point numbers are incapable of precisely representing most decimal fractions, so when you use them to perform calculations the errors build up into incorrect results. The Decimal class in the standard library is the way to avoid these errors in Python:

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