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 |