Q:

Percent Operator and Floating Point Values

When I run the code
System.out.println(12%5)

It always, without fail, prints out 2.  But, if it try this:
System.out.println(2%0.1)

It prints out 0.0999999999999999.  Im trying to use the % operator to round a number down to a given interval, but if the interval is a decimal, it always glitches like this.  What alternatives exist? 
Thanks. 
EDIT: The code i'm using to round to the nearest interval is this:
value -= value%0.1;

If value were to equal 0.567, value%0.1 would be 0.067, and 0.567-0.067 = 0.5. 

A:

An alternative is Math.round and/or Math.floor.   If you truly want to round to the nearest interval, use Math.round( num / interval ) * interval.   If you wish to round down to the next lower interval, use Math.floor( num / interval ) * interval. 
See https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#round(double)

