Geek Culture
Published in

Geek Culture

Decimals in Python: The 0.1 Problem

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:

--

--

--

A new tech publication by Start it up (https://medium.com/swlh).

Recommended from Medium

Atos AWS Gameday — Security

ChatOps/ChatBots at Centro

Deploy Django App with NGINX, Gunicorn, and Supervisor on Ubuntu Server

Picking an Identity and Access Vendor in 2020

How to run multiple mysql versions using docker — Magento 2

Kubernetes native Jenkins Operator

GIT — The Distributed Version Control System

What & How In Spring Boot Authentication

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
Timur Bakibayev

Timur Bakibayev

Professor, Ph.D. in CS, Almaty Management University

More from Medium

How to implement a Timeout functionality in Python

How to Work with Redis Sets, Lists, and Hashes in Python

Python Design Pattern- Behavioral | Part 3

Exceptions in Python.