If you use double or float , you should use rounding or expect to see some rounding errors. If you can't do this, use BigDecimal .

The problem you have is that 0.1 is not an exact representation, and by performing the calculation twice, you are compounding that error.

However, 100 can be represented accurately, so try:

double x = 1234; x /= 100; System.out.println(x);

which prints:

12.34

This works because Double.toString(d) performs a small amount of rounding on your behalf, but it is not much. If you are wondering what it might look like without rounding:

System.out.println(new BigDecimal(0.1)); System.out.println(new BigDecimal(x));

prints:

0.100000000000000005551115123125782702118158340454101562 12.339999999999999857891452847979962825775146484375

In short, rounding is unavoidable for sensible answers in floating point whether you are doing this explicitly or not.

Note: x / 100 and x * 0.01 are not exactly the same when it comes to rounding error. This is because the round error for the first expression depends on the values of x, whereas the 0.01 in the second has a fixed round error.

for(int i=0;i<200;i++) { double d1 = (double) i / 100; double d2 = i * 0.01; if (d1 != d2) System.out.println(d1 + " != "+d2); }

prints