Decimals in Python: The 0.1 Problem

Timur Bakibayev, Ph.D.
Geek Culture
Published in
4 min readMay 15, 2022

--

Also, how Decimals work with PostgreSQL

Introduction

When you deal with any kind of assets, be that USD or BTC, you must be sure that not a single penny is lost.

What happens if the customer of your bank has 0.1 USD on his account? We need to somehow store a floating point number. And for computers, it is all zeroes and ones.

0.1 is one-tenth, or 1/10. To show it in binary — that is, as a bicimal — divide binary 1 by binary 1010, using binary long division:

--

--