I’m starting today a new series of articles called Classical Issues. In it, I’ll address, one after the other, classical issues encountered through my software engineering years.
This first article is targeted to demystify computing and give some best practices for an enterprise application. By enterprise application, we mean an application working on things like money, prices and quantities. It will be in two parts. This one is about explaining the root of the problem. The second one will show how to handle it in Java and .Net.
Bill is developing a software doing commission payments. He needs to add 1.2$ to each transaction. He codes a method doing just that and the unit test coming along.
@Test
public void testAddCommission() {
double actual = addCommission(1000000.1);
assertEquals(1000001.3, actual, 0);
}
public static double addCommission(double nominal) {
return nominal + 1.2f;
}
java.lang.AssertionError: expected:<1000001.3> but was:<1000001.3000000477>
“Darn! It’s not working!”.
What’s going on?
(more…)