Hi, part of an application I'm writing needs to increment a double by 0.0001, however the application seems to give the wrong result
for example I'm expecting
Code:
double currentVal = -0.0003;
double increment = 0.0001;
for( int i = 0; i < 6; i++)
{
System.out.println(currentVal);
currentVal = currentVal + increment;
}
to return...
Code:
-3.0E-04
-2.0E-04
-1.0E-04
0.0
1.0E-04
2.0E-04
however it prints out..
Code:
-3.0E-4
-1.9999999999999998E-4
-9.999999999999998E-5
2.710505431213761E-20
1.0000000000000003E-4
2.0000000000000004E-4
Please can anyone help?
TIA