I'm fairly new to java but have some experience of coding (mostly PHP and some C++).
I'm having some trouble with calculations in my program. When I run the following code:
public class Test {
public static void main(String[] args) {
double number = 2 - (0.10 + 1.05);
System.out.println( number );
if( number < 0.85 ) System.out.println("to small");
}
}
My output is as follows:
run:
0.8499999999999999
to small
BUILD SUCCESSFUL (total time: 0 seconds)
I'm expecting 2 - ( 0.10 + 1.05 ) to be equal to 0.85 but for some reason it's not. Does anyone know why it would behave like this?
I'm using netbeans to code version 7.3.1 and jdk7u25 on Windows 8 if that is important. If there is anything else I should add please tell.
/Chris