this will truncate a float

int i;

float f = 3.456;

i = (int)f;

this will round a float:

int i;

float f = 3.456;

i = (int)(f + 0.5);

changing:

OurVariable = MyVariable + YourVariable;

to:

OurVariable = (int)(MyVariable+0.5) + (int)(YourVariable+0.5);

should do it.

Rounding to a specific number of digits:

try

float f = ((int)(3.45678 * 100))/100);

the (int)(3.45678 * 100) evaluates to 345 and dividing by 100 gives 3.45.

For n decimal places multiply and divide by 10^n. of Course the limits of precision for floats and doubles still have to be taken into consideration.

int i;

float f = 3.456;

i = (int)f;

this will round a float:

int i;

float f = 3.456;

i = (int)(f + 0.5);

changing:

OurVariable = MyVariable + YourVariable;

to:

OurVariable = (int)(MyVariable+0.5) + (int)(YourVariable+0.5);

should do it.

Rounding to a specific number of digits:

try

float f = ((int)(3.45678 * 100))/100);

the (int)(3.45678 * 100) evaluates to 345 and dividing by 100 gives 3.45.

For n decimal places multiply and divide by 10^n. of Course the limits of precision for floats and doubles still have to be taken into consideration.