delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/06/12:47:27

From: nospam AT miyares DOT slip DOT duq DOT edu (Real Email in Sig!)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: how to convert float ->int?
Date: 4 Jun 1997 19:49:55 GMT
Organization: Duquesne University, Pittsburgh, PA
Lines: 20
Message-ID: <5n4gt3$avg@news.duq.edu>
References: <01bc6dff$6cbac9c0$10ee13cb AT bbs> <01bc6d5d$4afb4aa0$LocalHost AT vpoulain>
NNTP-Posting-Host: miyares.slip.duq.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

POULAIN Vincent (vpoulain AT club-internet DOT fr) wrote:
: > whats the best way of converting from float to int?
: 
: I do use a simple way :
: 
: int a;
: float b=3.14;
: 
: a=b;
: 
: Fine, isn't it ?
: Only if you want the integer part of your float.
: If you want a rounded value, this will not work of course :-)

How about a=(b+0.5); for a rounded answer?  Seems right, but I've been
wrong on easier stuff before.

-- 
E M A I L :   substitute 'eNn' 'Oh' 'eSs' 'Pee' 'Aay' 'eMm'    
                with 'Kay' 'aRe' 'yoU' 'eSs' 'Tea' 'whY'

- Raw text -


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