How to make a value to nearest ten (e.g. 47 to 50 or 43 to 40)
How to make a value to nearest ten (e.g. 47 to 50 or 43 to 40)
Please help me for VB6.
Re: How to make a value to nearest ten (e.g. 47 to 50 or 43 to 40)
something like this:
vbcode Code:
'uses the modulus operataor to give the remainder when toBeRounded is divided by 10
lastDigit = toBeRounded Mod 10
'assues 5 means round up and 4 is round down
If lastDigit >= 5 Then
roundedValue = toBeRounded - lastDigit + 10
Else
roundedValue = toBeRounded - lastDigit
End If
Re: How to make a value to nearest ten (e.g. 47 to 50 or 43 to 40)
Code:
MsgBox Round(47 / 10) * 10
MsgBox Round(43 / 10) * 10
Re: How to make a value to nearest ten (e.g. 47 to 50 or 43 to 40)
another way (with 5 rounding up):
Code:
Dim N As Long
N = 45
Debug.Print (N \ 10 + (N Mod 10) \ 5) * 10
Re: How to make a value to nearest ten (e.g. 47 to 50 or 43 to 40)
Oh yea, i forgot about the round command... i should really install my vb6 instead of still using vb5 :)
Re: How to make a value to nearest ten (e.g. 47 to 50 or 43 to 40)
NearestTen = CLng(Value / 10) * 10
Note that this will take 45 down to 40. If you want the midpoint to always go up, then use this:
NearestTen = 10 * Int((Value + 5) / 10)