views:

94

answers:

1

This is a simple question:

Is this a correct way to get an integer part from a float division?

int result = myFloat / anInteger;

this is working, but I am not sure if it is the best way.

thanks for any help.

+6  A: 

To truncate:

int result = (int)(myFloat / anInteger);

Other conversion options:

#include <math.h>
int result = (int)ceilf(myFloat / anInteger);
int result = (int)roundf(myFloat / anInteger);
int result = (int)floorf(myFloat / anInteger);
KennyTM
thanks!!!!!!!!!!!
Digital Robot