www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/31/23:53:42

From: Ian Miller <itmiller AT dera DOT gov DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Round function?
Date: 28 Oct 1998 18:05:31 +0000
Organization: Defence Evaluation & Research Agency
Message-ID: <87vhl4k1ec.fsf@hasn.dera.gov.uk>
References: <36374585 DOT CADABD29 AT mindspring DOT com>
NNTP-Posting-Host: 146.80.115.106
X-Newsreader: Gnus v5.5/Emacs 20.3
Lines: 24
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Derek Greene <notsotopcoder AT mindspring DOT com> writes:

> Is there a functionf or rounding off real numbers when casting to
> integers or will a normal type cast do the trick? TIA

Depending on what you want to do one of
	(int) realnumber
	(int) (realnumber + 0.5)
might be suitable. Of course, you might want to consider whether or not
realnumber is positive or negative as well. And if you wanted to stay
in floating point, floor() and ceil() in the standard C library are
probably useful.

Anyway, ask this sort of question in a C programming newsgroup next time.
This is rather off topic in these parts.

Also you might want to consider getting a basic C book. Unless one is
learning C by trial and error there is no realistic alternative ;)

Ian
-- 
Ian Miller, Dorset, UK
The views expressed above are those of the writer and do not represent the
views, policy, or understanding of any other person or official body.

- Raw text -


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