I need to round a value up to the nearest multiple of 2.5.
For example:
6 –> 7.5
7.6 –> 10
etc.
This seems like the best way to do this?
Function RoundToIncrement(ByVal originalNumber As Decimal, ByVal increment As Decimal) As Decimal Dim num = Math.Round(originalNumber / increment, MidpointRounding.AwayFromZero) * increment If originalNumber Mod increment <> 0 And num < originalNumber Then num += increment End If Return num End Function
Divide the number by 2.5, round up to the nearest integer, then multiply the result by 2.5.
You’re close.
Math.Ceiling will always round non-integers up, so you don’t need the post-adjustment.