views:

160

answers:

3

Hey all,

I've created a game which gives a score at the end of the game, but the problem is that this score is sometimes a number with a lot of digits after the decimal point (like 87.124563563566). How would I go about rounding up or down the value so that I could have something like 87.12?

Thanks!

+9  A: 

Try using Math.Round. Its various overloads allow you to specify how many digits you want and also which way you want it to round the number.

Zach Johnson
And you most probably want to use `Math.Round(87.123453563566, 2, MidpointRounding.AwayFromZero);`.
0xA3
+3  A: 
double test2 = 87.2345524523452;
double test3 = Math.Round(test2, 2);
Charles Gargent
+1  A: 

Use Math.Ceiling(87.124563563566) or Math.Floor(87.124563563566) for always rounding up or rounding down. I believe this goes to the nearest whole number.

Jim