Skip to content

Archive

Numerical Computing

2 articles
Python 04 Sep 2026 10 min read

Use Decimal for Exact Base-10 Arithmetic in Python

A price of 0.10, a tax rate of 8.25%, and a total rounded to cents look like ordinary numbers. But the representation you choose determines which arithmetic rules your program actually follows. Python’s float is binary floating point. It is excellent for measurements, graphics, scientific calculations, and many other workloads where small approximation is expected. The problem appears when your domain requires values and rounding rules expressed in base 10.

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.