Python
03 Sep 2026
9 min read
Use Decimal for Predictable Base-10 Arithmetic in Python
Many Python programs can use float without trouble. Measurements, graphics, statistics, and scientific calculations often benefit from fast binary floating-point arithmetic. Problems appear when the data itself is defined in decimal terms and exact decimal values matter. A price such as 19.99, a tax rate such as 7.5%, or a quantity rounded to two decimal places may need rules that match decimal arithmetic rather than the binary representation used by float.