When I wrote a simple program to read and print a number using float, I came across some unexpected results.
In the following program when I entered a number 100.62, the result I got was 100.620003. Only upto eight digits the value showed correctly. Even when I tried different numbers the issue persisted. Why is this? Is there a way to overcome this problem other than by limiting the decimal points.
And also is there a way to print a digit as it is? ie; if I enter 100.62 it should print 100.62 and if enter 100.623 it should print 100.623 (not 100.620000 and 100.623000).
int main (void)
{
    float i;
    printf ("Enter a number : ");
    scanf ("%f", &i);
    printf ("You entered the number : %f", i)
    return 0;
}
 
     
     
    