Quote:
Originally Posted by Salik Syed
The problem with using a cast when trying to round is that all it does is remove the bits holding the decimal part of the number, this is not equivalent to rounding.
double number = 12.8743;
int val;
val = (int) number;
val now equals 12 ... clearly not the result you want.
You could use math.Round or just write your own function
public int round(double val)
{
if(val-(int)val>=.5)
{
return (int)val+1;
}
else {
return (int)val;
}
}
|
math.Round is a java comand...doesnt work in C
