decimal module
Python's standard library module for exact decimal arithmetic, used where binary floats would round wrongly, such as money.
In more detail
A Decimal stores 1.178 exactly and lets you choose the rounding rule. Many systems instead keep money as whole numbers of the smallest unit, such as pence.
Related terms
- floating-point number — A number with a fractional part stored in binary, which can only approximate most decimal values.
- rounding — Turning a number with a fractional part into a whole number by a chosen rule, such as nearest, towards zero or half to even.
Taught in
- Making Failures Explain Themselves — Automated Testing, TDD & Quality Engineering