|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#6
|
|||
|
|||
|
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; } } |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |