home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!gatech!concert!sas!mozart.unx.sas.com!walker
- From: walker@twix.unx.sas.com (Doug Walker)
- Subject: Re: Stupid C question
- Originator: walker@twix.unx.sas.com
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <C01C2K.AxK@unx.sas.com>
- Date: Tue, 29 Dec 1992 19:13:32 GMT
- References: <ad99s461.037k@sycom.mi.org>
- Nntp-Posting-Host: twix.unx.sas.com
- Organization: SAS Institute Inc.
- Lines: 26
-
-
- You say casting always seems to return a zero... I would need
- to see your code to find out why. Is your floating point number
- greater than 1.0 in any case? The following code should do
- what you want:
-
- ...
- double x;
- int i, j;
- ...
- i = (int)x; /* Convert with truncation */
- ...
- j = (int)(x+0.5); /* Convert with rounding */
-
- In the above examples, if "x" is 0.3, you'll get 0 for both
- "i" and "j". If "x" is 0.7, you'll get 0 for "i" but 1 for "j".
-
- --
- *****
- =*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
- *|. o.| || 1200/2400/9600 Dual
- | o |// For all you do, this bug's for you!
- ======
- usenet: walker@unx.sas.com bix: djwalker
- Any opinions expressed are mine, not those of SAS Institute, Inc.
-
-