Geek Culture
Published in

Geek Culture

Decimals in Python: The 0.1 Problem

Also, how Decimals work with PostgreSQL


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:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store