Q:

Is multiplying by 0.0000001 the same as dividing by 10000000?

In Java, is multiplying a double by 0.0000001 the same as dividing it by 10000000? My intuition is that there could be a difference because 0.0000001 cannot be represented exactly in a double.

A:

No it's not the same for the reason you mentioned. Here's an example:
double x = 894913.3;
System.out.println(x * 0.0000001);    // prints 0.08949133
System.out.println(x / 10000000);     // prints 0.08949133000000001

Using a BigDecimal, we can see the difference between the two values:
System.out.println(new BigDecimal(0.0000001));
System.out.println(new BigDecimal((double)10000000));

Ouput:
9.99999999999999954748111825886258685613938723690807819366455078125E-8
10000000

