andy-h
12/10/2014 - 9:15 PM

VBA function to round a number ending in 5 the traditional way, instead of the "round to even" logic. Unfortunately, this is significantly s

VBA function to round a number ending in 5 the traditional way, instead of the "round to even" logic. Unfortunately, this is significantly slower.

Function TradRound(val As Double, Optional places As Integer) As Double
    
    Dim divisor As Double
    Dim val2 As Double

    If IsMissing(places) Then places = 0

    divisor = 10 ^ places
    val2 = val * divisor - Int(val * divisor)

    If val2 = 0.5 Then
        TradRound = (Int(val * divisor) + 1) / divisor
    Else
        TradRound = Round(val, places)
    End If
    
End Function