Home

Visual Basic Built-In Functions: Int/Fix

  

Description

If you have a decimal number but are interested only in the integral part, to assist you with retrieving that part, the Visual Basic language provides the Int() and the Fix() functions. Their syntaxes are:

Public Shared Function Int( _
    ByVal Number As { Double | Integer | Long | 
		      Object | Short | Single | Decimal }) _
    As { Double | Integer | Long | Object | Short | Single | Decimal }
Public Shared Function Fix( _
    ByVal Number As { Double | Integer | Long | 
		      Object | Short | Single | Decimal }) _
    As { Double | Integer | Long | Object | Short | Single | Decimal }

Each function must take one argument. The value of the argument must be number-based. This means it can be an integer or a floating-point number. If the value of the argument is integer-based, the function returns the (whole) number. Here is an example

Public Module Exercise

    Public Function Main() As Integer
        Dim Number As Integer

        Number = 286345
        MsgBox(Int(Number))

        Return 0
    End Function

End Module

This would produce:

Int

If the value of the argument is a decimal number, the function returns only the integral part. Here is an example

Public Module Exercise

    Public Function Main() As Integer
        Dim Number As UInteger

        Number = 7942.225 * 202.46
        MsgBox(Int(Number))

        Return 0
    End Function

End Module

This would produce:

Int

 

This function always returns the integral part only, even if you ask it to return a floating-point-based value. Here is an example:

Public Module Exercise

    Public Function Main() As Integer
        Dim Number As Single

        Number = 286345.9924
        MsgBox(Int(Number))

        Return 0
    End Function

End Module

This would produce:

Int

 
 
     
 

Home Copyright © 2008-2016, FunctionX, Inc.