tags:

views:

121

answers:

2

Hello,

I have this (row and count are parameters):

(int)Math.Round(count / (decimal)rows, MidpointRounding.AwayFromZero)

if the result is 1.2, I'd lire return 2; 5.6 ---> 6; 79.9 ---> 80; 85.01 ---> 86

All the time the unit above, an int, not decimal.

An idea ?

Thanks,

+10  A: 

Math.Ceiling is your friend

spender
Wow, I literally typed exactly this...
John Rasch
'Great minds...' or is it 'Fools little differ'? ;)
spender
grrrr I missed this :( .... thanks !
Kris-I
A: 

Eric Lippert's answer put it quite well.

Jesse C. Slicer
@Eric: excellent point. And that point makes your original point of knowing your requirements before blindly applying a solution.
Jesse C. Slicer
Sorry, I was not thinking and typing at the same speed there in my now-deleted comment. I said it backwards. What I meant to say was that yes, my answer provides a solution that always rounds up, like Math.Ceiling, which is in contrast to "midpoint rounding away from zero" in the poster's question. If you want a solution that stays in integers, that's a good one.
Eric Lippert