home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / amiga / programm / 17858 < prev    next >
Encoding:
Internet Message Format  |  1992-12-28  |  1.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!hyperion!desire.wright.edu!fheitkamp
  2. From: fheitkamp@desire.wright.edu
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Stupid C question
  5. Message-ID: <1992Dec28.070426.6366@desire.wright.edu>
  6. Date: 28 Dec 92 07:04:26 EST
  7. References: <ad99s461.037k@sycom.mi.org>
  8. Distribution: world
  9. Organization:  Wright State University 
  10. Lines: 32
  11.  
  12. In article <ad99s461.037k@sycom.mi.org>, ad99s461@sycom.mi.org (Alex Deburie) writes:
  13. > Okay, I've had SAS-C 6.0 for about 2 weeks and I'm very pleased. Between GST's 
  14. > and the Workbench interface, I doubt I could ask for a better introduction to 
  15. > C on the Amiga.
  16. > However, I have one very stupid (simple?) question. HOW DOES ONE COVERT A 
  17. > FLOATING POINT VALUE TO AN INTEGER???!!!  I see functions like modf(), but 
  18. > still that returns the integral part of the number as a float. And casting 
  19. > seems to always return a 0!
  20.  
  21.     One simple way is to use a cast:
  22.  
  23.     float f1;
  24.     int   i2;
  25.  
  26.     i2 = ( int )f1;
  27.     you can also do a simple rounding that will work for positive
  28.     numbers:
  29.     i2 = ( int )(f1 + 0.5);
  30.  
  31.     This "casting" is very important to know with C.
  32.  
  33. > What should I do? Go back to BASIC?? ;^)
  34.  
  35.     No.  Noooo.  Not BAAAASIIIC!!!
  36.  
  37. >      -- Alex Deburie
  38. >         ad99s461@sycom.mi.org
  39. Fred Heitkamp,  ** Not an organization **
  40.  
  41.