Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   unexpected output value of floating type value (http://www.go4expert.com/forums/unexpected-output-value-floating-type-t8903/)

shyam_oec 19Feb2008 01:48

unexpected output value of floating type value
 
#include<stdio.h>
main()
{
float i=65.8;
printf("i= %f",i);
}

with reference to the above code,
output of this prgogram is i=65.800003

as i expected to be i=65.800000
can u explain why?

technosavvy 19Feb2008 11:05

Re: unexpected output value of floating type value
 
it is not an unexpected output...
remember everything is stored at the end of the day as binary number only...

now try representing it 65.8 in binary...u can only get close to 65.8 and never equal to 65.8...

make it
Code:

double i = 65.8
and ur problem will be resolved as the resolution of the number increases and hence u see the truncated output which is 65.8 !!


All times are GMT +5.5. The time now is 06:13.