CodeItBetter Programming Another VB Programming Blog

How to round off to the nearest 10 but not least, for example a) 10 would stay as 10 b) 11 would be 20 c) 3 would be 10 d) 22 would be 30 (in two ways)

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
'Math - How to round off to the nearest 10 but not least, for example a) 10 would stay as 10 b) 11 would be 20 c) 3 would be 10 d) 22 would be 30 (in two ways)
Sub Main()
    'Method: 1
    Dim X As Integer, Y As Integer
    Y = InputBox("Enter the number")
    X = ((Y \ 10) * 10) + IIf(Y Mod 10, 10, 0)
    Debug.Print X
 
    'Method: 2
    Dim X As Integer, Y As Integer
    Y = InputBox("Enter the number")
    X = -Int(-Y / 10) * 10
    Debug.Print X
End Sub
Filed under: Math Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.