+ 3
Why x and y are not equal?
3 Answers
+ 5
It's simple a double is not a float they are diffrent types try if((float)x==y){};
+ 3
Add this to your code:
System.out.println ( x - y);
System.out.println (x + y);
You'll see you don't get 0 or 6.2.
This is because there is a little bit less than what you insert and the difference of what you insert in float is less than double I think or opposite.
+ 2
since the binary hardware representation of decimal numbers is only possible with some error (inaccuracy) that depends on the number of bits used.
double x=3.1d;
float y=3.1f;
String f = "%.16f\n";
System.out.printf(f, x); // 3.1000000000000000
System.out.printf(f, y); // 3.0999999046325684