Possible Duplicate:
Floating point issue in C
#include<stdio.h>
main()
{
int a,b;
float f;
scanf("%2d%3d%4f",&a,&b,&f);
printf("%d %d %f",a,b,f);
}
When i run this program and input 2 4 56.8 ,it gives output 2 4 56.799999…..but I would expect 2 4 56.8….why is it so???
That is correct. Floating point numbers are approximations. Just as 0.33333333 is an approximation to 1/3, 56.7999999 is an approximation for 56.8. There is no exact floating point representation for 0.1.
See some of what has been written: