View Single Post
  #7   Spotlight this post!  
Unread 15-12-2006, 18:04
teh_pwnerer795 teh_pwnerer795 is offline
Registered User
AKA: !!Mitch!!
FRC #1392
Team Role: Programmer
 
Join Date: Nov 2006
Rookie Year: 2006
Location: Ajax, Canada
Posts: 142
teh_pwnerer795 is just really niceteh_pwnerer795 is just really niceteh_pwnerer795 is just really niceteh_pwnerer795 is just really nice
Send a message via MSN to teh_pwnerer795 Send a message via Yahoo to teh_pwnerer795
Re: Rounding numbers

Quote:
Originally Posted by Salik Syed View Post
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
__________________
Great Art is Created; Master Pieces are Stolen

[n00b]Teh_Foxdonut teh_pwnerer795 - CounterStrike:Source