Windows Mobile 2003Pocket PC 2002Windows Mobile 5Windows Mobile 6.NET CFWindows MobileBeginnerDevVisual Basic
MidpointRounding.AwayFromZero functionality in .Net Compact Framework
The Math.Round function in the Compact Framework only allows for ToEven behavior, not the AwayFromZero functionality as listed here:http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx[^]This code will allow you to emulate the MidpointRounding.AwayFromZero functionality of...
The
http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx[^]
This code will allow you to emulate the
Math.Round
function in the Compact Framework only allows for ToEven
behavior, not the AwayFromZero
functionality as listed here:http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx[^]
This code will allow you to emulate the
MidpointRounding.AwayFromZero
functionality of the full .NET Framework. Public Function RoundAwayFromZero(ByVal startValue As Decimal, ByVal digits As Integer) As Decimal
Dim decimalValue As Integer
startValue *= CDec(10 ^ (digits + 1))
decimalValue = CInt(Decimal.Floor(startValue) - Decimal.Floor(startValue / 10) * 10)
startValue = Decimal.Floor(startValue / 10)
If decimalValue >= 5 Then
startValue += 1
End If
startValue /= CDec(10 ^ (digits))
Return startValue
End Function