DEV Community

Discussion on: Why 1% - 1% Isn't Zero in Your Calculator (And What It Really Means)

Collapse
 
kvetoslavnovak profile image
kvetoslavnovak • Edited

If I remember my math classes correctly 1% - 1% = 0.0099. That is becuase it can be written also as 0.01 − 0.0001.
More obvious it si in this example 5 - 1% = 4.95 and 5 - 100% = 0. So 1% - 100% = 0 because we are substacting the whole (i.e. 100%) number from the number.
Same as for subtraction applies to multiplication, 1% * 1% can be aslo written as 0.01 * 0.0001..
Not sure if this has anything to do with calculators or computer scinence at all.
Just very basic math principles and rules how % calculations work.

Collapse
 
rez1coder profile image
Rezoan

Yes, I agree! But some calculators, like KCalc, still produce 0 in cases like this. I noticed it myself on Manjaro Linux. Likely a quirk in how they handle percentages rather than basic math principles. 😊

Collapse
 
kvetoslavnovak profile image
kvetoslavnovak • Edited

Oh, I see. That is quite interesting.
I have recently discovered that lots of stuff in Windows 11 is done using React Native. So we may be lucky not havig 0.1 + 0.2 = 0.30000000000000004, hahaha.