I've been using this code to round off values but there is a problem when I try to round to a decimal value. RoundToNearestVal = 0.1 and a Double or Variant type. It takes the value as 0 so I get a division by 0 error. What am I doing wrong here?
Code:Public Function RoundToNearest(NumberToRound, RoundToNearestVal) 'Function rounds up or down to the nearest value RoundToNearest = RoundToNearestVal * (NumberToRound \ RoundToNearestVal) If Abs(NumberToRound - RoundToNearest) > RoundToNearestVal / 2 Then If NumberToRound >= 0 Then RoundToNearest = RoundToNearest + RoundToNearestVal Else RoundToNearest = RoundToNearest - RoundToNearestVal End If End If End Function




Reply With Quote