Why floating point numbers are accurate while arithmetic operations are not? I mean doesn't compiler rounds to the nearest number to represent double numbers not only arithmetic operation results?
double a = 0.1;
double b = 0.2;
System.out.println(a);
System.out.println(b);
System.out.println(a + b);
outputs;
0.1
0.2
0.30000000000000004
What I expected;
0.10000000000000001
0.20000000000000003
0.30000000000000004
EDIT: What is the difference between these operations;
double a = 0.3;
double b = 0.1 + 0.2;
System.out.println(a); //0.3
System.out.println(b); //0.300000000000004