delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/28/20:30:47

From: pjotr AT wlink DOT net (pjotr)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [DESPERATE newbie]How to round a float to an int?
Date: Fri, 29 Jan 1999 01:09:07 GMT
Organization: Posted via RemarQ, http://www.remarQ.com - Discussions start here!
Lines: 24
Message-ID: <36b10996.4620855@news.w-link.net>
References: <78nicq$ph6$1 AT zingo DOT tninet DOT se> <199901272251 DOT RAA01103 AT envy DOT delorie DOT com>
NNTP-Posting-Host: 208.151.227.220
X-Trace: 917572105 T.3QWX1FWE3DCD097C usenet54.supernews.com
X-Complaints-To: newsabuse AT remarQ DOT com
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Wed, 27 Jan 1999 17:51:47 -0500, DJ Delorie <dj AT delorie DOT com> wrote:

>
>> 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 */

wouldn't the two lines above create warnings though?
Instead I would write:

	i = (int) f;
	i = (int) (f + 0.5);

Cheers,
Pjotr

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019