From: Frodo Baggins Newsgroups: comp.os.msdos.djgpp Subject: Re: Floating point accuracy Date: Thu, 6 Mar 1997 10:29:27 +0000 Organization: Instituto Superior Tecnico Lines: 26 Message-ID: References: <5ff7e6$974 AT cronkite DOT ocis DOT temple DOT edu> NNTP-Posting-Host: alfa.ist.utl.pt Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Transfer-Encoding: QUOTED-PRINTABLE In-Reply-To: <5ff7e6$974@cronkite.ocis.temple.edu> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On 3 Mar 1997, David Tucker wrote: > I have a question. >=20 > When I do a calculation such as: >=20 > =09X =3D a / b; // where int a =3D 994 and int b =3D 1000 > =09=09or > =09cout << "X =3D " << a / b << endl; >=20 > my result is 0. >=20 You are doing the operation with ints! If you divide 994 by 1000 you will= =20 get 0.994 .... now try to cast that to (int) and see what you get, you=20 will get zero, because that=B4s the way computers truncate! You should then do like this: X =3D (float)a / (float)b // and X MUST be a float or double=20 Hope it helped! :)