Admit it, as a developer, we all assume tip calculator is simple. There are probably hundreds of tip calculator apps on Android and iPhone. We made our tip calculator app simply because it is a good app to start. We have a new design of this app a couple of months ago.  It looks cool and very functional. I thought we are done with it, until one day, a guy named Sean left a comment on our app, saying “Can’t add 9.95+1.00(=10.94?) 10% tip”. I didn’t really pay much attention until I grab my tipcal app and did exactly what Sean said. I entered 9.95 as the bill, adjusted tip percentage to 10%, the app shows $1 as tip but the total is 10.94 which is wrong.

My first thought is it is a rounding error. After debugging, I realized it is not the case. 10% of 9.95 is 0.995, so total should be 9.95 + 0.995 = 10.945. If it rounds, it should still be 10.95, not 10.94. It turned out the root reason is when doing 9.95 + 0.995 in computer word, the result is 10.944999999999999. After rounding it becomes 10.94, not 10.95 as expected.

I downloaded a few other popular tip cal apps, on Android and on iPhone. To my surprise, all of them have the same error. See below. It is very common for developers to do it this way. We were trained to keep the precision at the maximum during the intermediate steps and only round at the final step. That’s why all apps have the same error. However from user point of view, 9.95 + 1 = 10.94 is wrong. Even it is just one cent difference, developers have no excuse for it.

And here is our tip cal app after fixing the bug. Thanks Sean.

About these ads