Hello archyb,
It would be worth doing some reading about repeating decimals. There is lot's of information online.
Heres the gist of it though:
A decimal representation of a real number is called a repeating decimal (or recurring decimal) if at some point it becomes periodic: there is some finite sequence of digits that is repeated indefinitely. For example, the decimal representation of 1/3 = 0.3333333... (spoken as "0.3 repeating", or "0.3 recurring") becomes periodic just after the decimal point, repeating the single-digit sequence "3" infinitely. A somewhat more complicated example is 3227/555 = 5.8144144144..., where the decimal representation becomes periodic at the second digit after the decimal point, repeating the sequence of digits "144" infinitely.
The link provided in your other forum post is also useful:
What Every Computer Scientist Should Know About Floating-Point Arithmetic
I know it's an awful lot of reading and to a beginner it can be very daunting but even just a quick read will help you pick up some basic information that helps lay the foundation for the knowledge you need to acquire.
I also suggest reading -
Java theory and practice: Where's your point?
You can round your answer to get the expected output:
public class DoubleTest {
/**
* JavaProgrammingForums.com
*/
public static void main(String[] args) {
double x = 45.32;
double y = 45.31;
double answer = (x - y);
answer = Math.round(answer*100)/100.0d;
System.out.println(answer);
}
}