Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!hsdndev!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Simple atof() question Message-ID: <15522@smoke.brl.mil> Date: 20 Mar 91 21:19:29 GMT References: <1214@caslon.cs.arizona.edu> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 19 In article <1214@caslon.cs.arizona.edu> armstron@cs.arizona.edu (Jim Armstrong) writes: >How can I get atof() to return a float instead of a double? You can't; it always returns type "double". >When I run this simple program I get n = 37.549999 instead of >n = 37.55. What am I doing wrong? That's a different question. There's nothing particularly wrong with your program, other than failing to return a value from main(). Note that the float argument to printf() is promoted to a double, but that's not a problem. I think your real problem is that you think that the value 37.55 can be represented exactly in a binary floating-point representation. Somewhere along the way, probably within atof(), you're picking up a small amount of "dirt" in the last bit or so of the internal representation. This is usual for floating-point; you should learn from this to not expect exactness when floating-point is involved.