Last active
March 22, 2017 16:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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