Go to Post Good engineering often comes down to knowing the difference between "better" and "good enough." - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Negative numbers? Calvin Programming 6 09-02-2005 10:46
Part Numbers DDRAngelKurumi Kit & Additional Hardware 1 29-01-2005 18:38
Random Numbers Astronouth7303 Programming 9 18-01-2004 21:39
Team Numbers archiver 2000 2 24-06-2002 00:24
Numbers at VCU Madison Regional Competitions 5 10-03-2002 02:26


All times are GMT -5. The time now is 01:20.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi