Floating-point numbers on a computer, like
java's double and float primitive types, are approximate values. There has to be a compromise between the precision of a value and the amount of memory it would take to represent it. Otherwise how could we represent a number like pi, which has an infinite number of digits?
This article (the document this link points to has been removed by IBM. The Internet Archive has an
archived copy. Keep in mind that this information is many years old and may not reflect the current state of art) is a good introduction to the concepts and pitfalls of floating-point numbers. Incidentally, java provides two classes in the
java.math classes for representing arbitrary-precision values, like when working with money.