by Pulsewave (25 Submissions)
Category: Math/Dates
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sun 29th December 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Round a number to the nearest anything you want. like if you wanted to round the number 53 to the nearest 5, it would round it up to 55.
'mynumber = 48
'mynumber = sround(mynumber, 45)
'now, after calling this mynumber will = 45.
Function sRound(number As Long, onum As Integer) As Long
Dim p As Long, r As Long, z As Long
p = number / onum
If InStr(1, CStr(p), ".") Then
r = Right(CStr(p), Len(CStr(p)) - InStr(1, CStr(p), "."))
p = Left(CStr(p), InStr(1, CStr(p), ".") - 1)
z = Round(CLng("." & r))
If z = 0 Then
sRound = (p * onum)
Else
sRound = ((p + 1) * onum)
End If
End If
If p = 0 Then p = 1
sRound = (p * onum)
End Function
No comments have been posted about Round a number to the nearest anything you want. like if you wanted to round the number 53 to the n. Why not be the first to post a comment about Round a number to the nearest anything you want. like if you wanted to round the number 53 to the n.