Simple atof() question
Brendan Kehoe
brendan at cs.widener.edu
Wed Mar 20 04:17:19 AEST 1991
In <1214 at caslon.cs.arizona.edu>, armstron at cs.arizona.edu writes:
>How can I get atof() to return a float instead of a double?
>When I run this simple program I get n = 37.549999 instead of
>n = 37.55. What am I doing wrong?
>[...]
>n = (float) atof(buf);
>printf("n = %f\n",n);
>[...]
I have a feeling it's got something to do with the way printf takes
its argument .. notice if ya do
printf("n = %.2f\n", n);
you do get 37.55.
--
Brendan Kehoe - Widener Sun Network Manager - brendan at cs.widener.edu
Widener University in Chester, PA A Bloody Sun-Dec War Zone
Now that we know he has ID, we could give him an account. finger bush at cs....
More information about the Comp.lang.c
mailing list