Subject: [PD] converting float to int
Date: gio, ago 15, 2002 at 12:45:17 -0700
Quoting J. Scott Hildebrand (jshildebrand@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