Not really positive what you mean, but it seems to work with other floats. If I do "System.out.println(5 % .25);" it will return 0. Thanks :)
–
hetelekSep 27 '11 at 0:36

1

He means exactly what he said. 0.1 cannot be represented in a IEEE-754 floating point. This is a classic computer science problem.
–
Oscar KorzSep 27 '11 at 0:37

0.25 can be represented because it is a power of 2 (2 ^ -2).
–
Oscar KorzSep 27 '11 at 0:38

2

@sh042067: and that's because 0.25 is 1/4 which can be represented exactly on a digital computer. Google about digital representation of floating point numbers. This is not a Java problem but a digital computer problem.
–
Hovercraft Full Of EelsSep 27 '11 at 0:38

Java (like most programming languages except COBOL) is making computations in the binary systems. I think 0.10 has such a unlucky binary representation that the result of your computation looks like this. I think it is best to avoid computing modulus of double or float and stick to integer or long to get better results.