From: "Sly" Newsgroups: comp.os.msdos.djgpp Subject: Re: Floating Point??? Date: 5 Mar 1997 06:20:21 GMT Organization: Sly Lines: 34 Message-ID: <01bc292d$d7fed300$8a081ecb@sly> References: <4b5_9703051119 AT softtech DOT brisnet DOT org DOT au> <5fin95$f8 AT news DOT ox DOT ac DOT uk> NNTP-Posting-Host: max0ppp08.bne.aussie.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp George Foot wrote in article <5fin95$f8 AT news DOT ox DOT ac DOT uk>... > Ron T Lewis (ron DOT t DOT lewis AT softtech DOT brisnet DOT org DOT au) wrote: > > : int main() > : { > : float a; > : a=4.00/5.00; > : printf("float = %.12f\n",a); > : return(1); > : } > : Ans = 0.800000011921 > > : The correct answer should be 0.800000000000 but he gets these extroneous > : numbers tacked on the end??? > > `float' numbers aren't that accurate; use `double's instead. Replace `float' > with `double' throughout, and change `%.12f' to `%.12lf', and you should get > the right answer. > > -- > George Foot > Merton College, Oxford. > floats are only precise up to about 6 digits or so. doubles are precise up to .. err .. is it 10? -- TTFN Sly (Steve)