Hi Guys,
I have a situation where a float calculation is made,
and the result is converted back to an integer.
Is there a neat solution to convert to the nearest integer,
rather than just copying the float to the integer to always round down?
So instead of this:
Code:
float afloat = 5.9;
int aninteger = 0;
aninteger = afloat; // aninteger = 5
Something neater, and hopefully faster than this:
Code:
float afloat = 5.9;
int aninteger = 0;
aninteger = afloat; // aninteger = 5
afloat = afloat - aninteger; // afloat = 0.9
if (afloat > 0.5) {aninteger++;} // aninteger = 6
Or is this the best I can hope for?
Cheers, Brek.