delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/06/17:18:28

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: how to convert float ->int?
Date: Fri, 06 Jun 1997 02:50:45 -0700
Organization: Alcyone Systems
Lines: 25
Message-ID: <3397DD75.57714DFC@alcyone.com>
References: <199705311842 DOT LAA03805 AT geocities DOT com>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Guilherme Silveira wrote:

> There's the way to convert from float to int:
> 
> Function FCVT (propabily Float Converter)
    ...

Bizarre.  First, this doesn't answer the question.  fcvt would convert a
double to a _string_, not an int.  Last I heard, "string" and "int" don't
mean the same thing.  Second, fcvt is Borland-specific and not ANSI C.  As
such, it's not a very good suggested, even if it solved the problem the
original poster was asking about.

The correct (and trivially simple) thing to do is a typecast:

    float f = /* ... */;
    int i = (int) f;

-- 
       Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
     "Covenants without the sword / are but words."
                                 / Camden

- Raw text -


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