Mail Archives: djgpp/1997/03/05/00:09:55
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 <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.
- Raw text -