September 2026
1051 pages
35h 4m
English
You’ll certainly remember the following example, which shows that calculation errors occur when using the built-in float data type:
>>> 1.1 + 2.23.3000000000000003
This is because the internal memory model of float cannot represent every decimal number; it can only approximate them to a certain accuracy.[ 121 ] These calculation errors are usually accepted for reasons of efficiency. In some cases, however, such as when calculating monetary amounts, it is particularly inconvenient that even simple floating-point numbers such as 1.1 and 2.2 cannot be represented exactly, and calculations with currency amounts therefore quickly become error-prone.
The decimal module contains the Decimal data type, which ...
Read now
Unlock full access