Is it possible to write a function that gets float values and convert them to integers?
int floatToInt(float val)
{
return val;
}
yes but this doesnt it return a float value?
Or just cast:
int(val)
C++ int constructor
or
(int) val
C cast syntax
But in a context that requires an int you can just use a float, the casting is implicit.
However the casting using truncation, not rounding, which is often the wrong thing to do.
So perhaps you want
int(round(val))
No its an int function so it must return int
MarkT:
However the casting using truncation, not rounding, which is often the wrong thing to do.
I am like a computer, I only do what I'm told to do.
thank you , i used the C syntax and it worked
I was wrong about round(), it already return int. Confusing it with Python's round()