home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!hyperion!desire.wright.edu!fheitkamp
- From: fheitkamp@desire.wright.edu
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Stupid C question
- Message-ID: <1992Dec28.070426.6366@desire.wright.edu>
- Date: 28 Dec 92 07:04:26 EST
- References: <ad99s461.037k@sycom.mi.org>
- Distribution: world
- Organization: Wright State University
- Lines: 32
-
- In article <ad99s461.037k@sycom.mi.org>, ad99s461@sycom.mi.org (Alex Deburie) writes:
- > Okay, I've had SAS-C 6.0 for about 2 weeks and I'm very pleased. Between GST's
- > and the Workbench interface, I doubt I could ask for a better introduction to
- > C on the Amiga.
- >
- > However, I have one very stupid (simple?) question. HOW DOES ONE COVERT A
- > FLOATING POINT VALUE TO AN INTEGER???!!! I see functions like modf(), but
- > still that returns the integral part of the number as a float. And casting
- > seems to always return a 0!
-
- One simple way is to use a cast:
-
- float f1;
- int i2;
-
- i2 = ( int )f1;
- you can also do a simple rounding that will work for positive
- numbers:
- i2 = ( int )(f1 + 0.5);
-
- This "casting" is very important to know with C.
-
- >
- > What should I do? Go back to BASIC?? ;^)
-
- No. Noooo. Not BAAAASIIIC!!!
-
- >
- > -- Alex Deburie
- > ad99s461@sycom.mi.org
- Fred Heitkamp, ** Not an organization **
-
-