TIL my calculator lied to me about how computers do math and I spent 3 hours debugging nothing | Coding For Beginners - Freelance Forum - The Community for Independent Professionals
TIL my calculator lied to me about how computers do math and I spent 3 hours debugging nothing
So I'm on like week two of learning Python, right? I wrote this tiny program that takes two numbers and spits out a total, just for practice. I typed in 0.1 plus 0.2 expecting 0.3 and the screen showed 0.30000000000000004. I sat there for three hours convinced my code was broken. I deleted lines, rewrote the whole thing from scratch, even restarted my laptop twice like that would somehow fix it. Then I googled it at 1am and found out computers store decimals in this weird way that makes tiny rounding errors happen. It's called floating point something, I still don't fully get it. What bugs me is my math teacher never mentioned this once in 12 years of school. Has anyone else run into this with their first programs or am I just behind everyone?