delorie.com/archives/browse.cgi | search |
Date: | Wed, 27 Jan 1999 17:51:47 -0500 |
Message-Id: | <199901272251.RAA01103@envy.delorie.com> |
From: | DJ Delorie <dj AT delorie DOT com> |
To: | djgpp AT delorie DOT com |
In-reply-to: | <78nicq$ph6$1@zingo.tninet.se> (rannugi@hotmail.com) |
Subject: | Re: [DESPERATE newbie]How to round a float to an int? |
References: | <78nicq$ph6$1 AT zingo DOT tninet DOT se> |
Reply-To: | djgpp AT delorie DOT com |
> Is there a function to round a float to an int(in c++)included in > the DJGPP package? I searched and searched but I couldn't find > one. HELP ME! There is no function to do it. The compiler just knows how to do it. int i; float f; i = f; /* truncates */ i = f + 0.5; /* rounds, for positive numbers */ You may want to look up the floor() and ceil() functions for doing various rounding operations on doubles before letting the compiler convert it to an int.
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |