I recently started learning java and this question keeps on bugging me..
class Example{
public static void main(String args[]){
double d;
d=4.1 % 1.1;
System.out.println("4.1%1.1 : "+d);
d=5.5 % 1.1;
System.out.println("5.5%1.1 : "+d);
}
}
the output for the above program is 4.1%1.1 : 0.7999999999999994 and 5.5%1.1 : 1.0999999999999996
but when we do these calculations by hand, we get 0.8 for the first one and 0 for the second one... why does this happen??
% gives the correct answer when integers are used in the expression..
class Example{
public static void main(String args[]){
int x;
x=10%17;
System.out.println("10%17 : "+x); **//prints 10**
}
}
can anyone pl explain what exactly happens here?