views:

34

answers:

1

In Silverlight the Math.Round() method does not contain an overload with 'MidpointRounding' parameter. What is the best approach to round a double away from zero in Silverlight in this case?

Example:

Math.Round(1.4) => 1

Math.Round(1.5) => 2

Math.Round(1.6) => 2

+1  A: 

Any number of "hacks" will do it, for example:

Public Shared Function SpecialRound(ByVal inVal) As Double
    if (inVal < 0)
        Return Math.Ceil(inVal-0.5)
    Return Math.Floor(inVal+0.5)
End Function

I do not know of a "good" way to do it.

MatsT