In Java the floating point arithmetic is not represented precisely. For example following snippet of code
float a = 1.2;
float b= 3.0;
float c = a * b;
if(c == 3.6){
System.out.println("c is 3.6");
} else {
System.out.println("c is not 3.6");
}
actually prints "c is not 3.6".
I'm not interested in precision beyond 3 decimals (#.###). How can I deal with this problem to multiply floats and compare them reliably?
Thanks much