Simple double calculations...
Hi there, it's me again asking basic Java questions ^^'
At some point in my program I have run into weird results when subtracting a hundredth to a double value.
I created this SSCCE to show what I'm talking about:
Code:
public static void main(String[] args) {
double value = 1.02;
System.out.println(value+" - 0.01 = "+(value-0.01));
value = 2.02;
System.out.println(value+" - 0.01 = "+(value-0.01));
value = 43.09;
System.out.println(value+" - 0.01 = "+(value-0.01));
value = 95.07;
System.out.println(value+" - 0.01 = "+(value-0.01));
value = 205.05;
System.out.println(value+" - 0.01 = "+(value-0.01));
}
Which returns:
Code:
1.02 - 0.01 = 1.01
2.02 - 0.01 = 2.0100000000000002
43.09 - 0.01 = 43.080000000000005
95.07 - 0.01 = 95.05999999999999
205.05 - 0.01 = 205.04000000000002
Can someone tell me why is this happening and how can be fixed?
Thanks in advance once again,
b0rt