|
-
Apr 7th, 2007, 02:34 PM
#1
Thread Starter
New Member
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.
-
Apr 7th, 2007, 02:54 PM
#2
Addicted Member
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
-
Apr 7th, 2007, 02:55 PM
#3
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
-
Apr 7th, 2007, 03:00 PM
#4
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
-
Apr 7th, 2007, 03:01 PM
#5
Addicted Member
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
-
Apr 7th, 2007, 03:02 PM
#6
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|