Skip to content

Instantly share code, notes, and snippets.

@wizard04wsu
Last active March 22, 2017 16:37
Show Gist options
  • Save wizard04wsu/91b1c1ff2f460016d303 to your computer and use it in GitHub Desktop.
Save wizard04wsu/91b1c1ff2f460016d303 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment