View Single Post
  #6   Spotlight this post!  
Unread 14-12-2006, 22:49
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
Re: Rounding numbers

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;
}
}
__________________
Team 701