Possible Duplicate:
Floating point arithmetic not producing exact results in Java
Float numbers in Java
Please see Code Below.
public class TestSum {
public static void main(String[] args) {
float a = 4.8f;//try with 4.7f
float b = 4.5f;//try with 4.6f
double sum = a + b;
System.out.println(sum);
}
}
(4.8f+4.5f) sum=9.300000190734863
But when, i tried (4.7f+4.6f)
it gives sum = 9.299999237060547
Again,
(1.8f+1.5f) sum=3.299999952316284.
(1.7f+1.6f) sum=3.3000001907348633.
But,
(2.8f+2.5f) sum=5.300000190734863.
(2.7f+2.6f) sum=5.300000190734863.
I want to Understand, how this works. Thanks in advance.