Simple atof() question

Jim Armstrong armstron at cs.arizona.edu
Wed Mar 20 01:52:35 AEST 1991


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?


#include <stdio.h>

main()
{

double atof();
char buf[10];
float n;

strcpy(buf,"37.55");
n = (float) atof(buf);
printf("n = %f\n",n);

}


-- 
Jim Armstrong			  "The nonpayment and subsequent abuse of
armstron at cs.arizona.edu		  socially powerless athletes is simply a
{uunet|noao}!arizona!armstron     form of modern-day slavery" --Rick Telander



More information about the Comp.lang.c mailing list