[PD] converting float to int

Carlo E. Prelz fluido at fluido.as
Thu Aug 15 23:59:07 CEST 2002

Subject: [PD] converting float to int
Date: gio, ago 15, 2002 at 12:45:17 -0700

Quoting J. Scott Hildebrand (jshildebrand at ucdavis.edu):

> inside my external i have
>   t_float secondfloat;
>   t_float firstfloat;
>
> because they're inlets. i need to convert those to int, basically i need
> to truncate the decimal part. how do i do that? thanks,

Maybe I did not get your question right. This is very elementary C.

If you want to just truncate the decimal part of a floating point
variable you just cast it to int:

int firstint=(int)firstfloat;
int secondint=(int)secondfloat;

If you want to have the nearest integer, this is what you need

int firstint=(int)(firstfloat+0.5);
int secondint=(int)(secondfloat+0.5);

In the hope of being useful...

Carlo

--
*         Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido at fluido.as             che bisogno ci sarebbe
*               di parlare tanto di amore e di rettitudine? (Chuang-Tzu)