Skip to main content

Round()

The round function will return a specified value to the nearest number, the default value is to the nearest 0, if you wish to the nearest decimal point the function would be Round(number, numer of decimals).  I haven't found a way to round to the nearest tenths or more (one way to get around this is first divide your number by 10, assuming you want to round to the nearest tenths, them do the default round and finally multiply by 10, see the last example).  Also the return value is the same type as the value that is being rounded, so if the number is a double the return value is a double.

Script

Sub Main
    Dim MyNumber As Integer
    MyNumber = 15.65
    MsgBox Round(MyNumber) 'return 16
End Sub

Sub Main
    Dim MyNumber As Integer
    MyNumber = 15.49
    MsgBox Round(MyNumber) 'return 15
End Sub

Sub Main
    Dim MyNumber As Double
    MyNumber = 15.65
    MsgBox Round(MyNumber, 1) 'return 15.6
End Sub

Sub Main
    Dim MyNumber As Double
    MyNumber = 15.65
    MsgBox Round(MyNumber, 2) 'return 15.65
End Sub

Sub Main
    Dim MyNumber As Double
    MyNumber = 15.65
    mynumber = mynumber / 10
    mynumber =      Round(MyNumber)
    mynumber = mynumber * 10
    MsgBox Round(MyNumber) 'return 20
End Sub

IDEAScript Language