Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!news.cs.indiana.edu!cs.widener.edu!brendan From: brendan@cs.widener.edu (Brendan Kehoe) Newsgroups: comp.lang.c Subject: Re: Simple atof() question Message-ID: <1991Mar19.181719.7821@cs.widener.edu> Date: 19 Mar 91 18:17:19 GMT Article-I.D.: cs.1991Mar19.181719.7821 References: <1214@caslon.cs.arizona.edu> Distribution: na Organization: Widener CS Dept Lines: 18 In <1214@caslon.cs.arizona.edu>, armstron@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@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@cs....