Mail Archives: djgpp/1998/10/31/23:53:42
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 -