From: Yamaha / XYZZ Newsgroups: comp.os.msdos.djgpp Subject: Re: Problems with DJGPP V2.01 - atof() function Date: Mon, 02 Dec 1996 12:25:59 -0700 Organization: XYZZ Software Co. Lines: 26 Message-ID: <32A32D47.7DE1@CS.ColoState.edu> References: <329e68a5 DOT 10316617 AT news DOT ua DOT pt> NNTP-Posting-Host: miro.vis.colostate.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp afonso AT inesca DOT inesca DOT pt wrote: > char string[]="1.13"; > int result; > ... > result = (int)(atof(string)*100); > ... > > I've got result = 112!!! not 113 as I wished, because > the function atof() return is 1.29999... not 1.13 (and I only have > an old i386). > I think that problem is a bug of DJGPP Library V2.xx. > Has someone noticed that problem and corrected it? If they > have, please let me know about it. Not a library bug. It's probably due to truncation. When you convert floating point values to integer values, there is no rounding done. Instead, everything after the decimal point is dropped. 1.1299999 * 100.0 is 112.9999, and will always be 112 when converted to an integer unless you purposely round up. -- Yamaha / XYZZ mailto:scriven AT CS DOT ColoState DOT edu mailto:scriven AT VIS DOT ColoState DOT edu http://www.vis.colostate.edu/~scriven/