If you go to a shop and buy 1.5 kg of sugar, you would think a computer database could save the number 1.5 without any issues. It turns out, it isn't that simple.

Here is what I learned today:

The Core Problem: Humans and Computers Count Differently
Humans count in Base-10. We use ten digits (0 to 9), so clean decimals like 0.1, 0.5, or 1.5 make perfect sense to us.

Computers, however, count in Base-2 (Binary). Their brains only understand 0s and 1s.

Because of this hardware limitation, a computer cannot cleanly save a normal human decimal like 0.1 using its standard number memory. To a computer, 0.1 turns into an endless, repeating loop of 0s and 1s that gets cut off. Because it gets cut off, standard computer math breaks. If you ask a computer to do 0.1 + 0.2, it doesn't give you 0.3. It gives you 0.30000000000000004!

While that tiny error seems small, if you calculate it thousands of times, your money vanishes or your stock numbers break.

How We Fix It: The SQLite vs. PostgreSQL Approach

To stop this corruption, our code and our database need to talk in exact human decimals, not computer binary.

Right now, I am using SQLite. SQLite is lightweight but it does not have a built-in exact decimal system - it defaults to those messy 0s and 1s. To fix this, we use a clever trick: we save our numbers as TEXT in the database. Text freezes the characters "1.5" exactly as they are so they don't warp. Then, we bring that text into Python and use a special tool called decimal.Decimal to do the math perfectly.

If I upgrade to a bigger database like PostgreSQL in the future, the code stays safe. Postgres actually has a native engine built just for human decimals. It saves the exact decimal directly on the disk, hands it to Python automatically, and Python does the exact same precise math.

The Takeaway is :-
The database and our code have two different jobs. The database acts like a secure filing cabinet to keep the numbers safe on the hard drive, and Python acts like the calculator doing the math in memory.

No matter what tools we use, both sides have to speak the same language so our data never gets corrupted. If you are building any system that tracks money or stock, never trust standard computer numbers!