O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

decimal

On most systems, the Python float data type is represented using a binary floating-point encoding such as the IEEE 754 standard. A subtle consequence of the binary encoding is that decimal values such as 0.1 can’t be represented exactly. Instead, the value is 0.10000000000000001. This inexactness carries over to calculations involving floating-point numbers and can sometimes lead to unexpected results (for example, 3*0.1 == 0.3 evaluates as False).

The decimal module provides generalized support for decimal floating-point numbers. These numbers allow for exact representation of decimals. In addition, parameters such as precision, significant digits, and rounding behavior can be controlled.

The decimal module defines two basic data types: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required