VBA Functions: Int and Fix

The VBA Int and Fix functions return the integer part of a number.

These two functions have the same effect on positive numbers, but when it comes to negative numbers, the Int function rounds towards the lower integer while Fix rounds towards the higher integer.

Usage:

Int(value)

Fix(value)


Example of Usage

Using the Int and Fix functions to convert different types of numeric values and better understand their difference when it comes to negative values:

Sub example()

    MsgBox Int(1) 'Returns: 1
    MsgBox Fix(1) 'Returns: 1
    
    MsgBox Int(-1) 'Returns: -1
    MsgBox Fix(-1) 'Returns: -1
    
    MsgBox Int(2.9) 'Returns: 2
    MsgBox Fix(2.9) 'Returns: 2
    
    MsgBox Int(-2.9) 'Returns: -3
    MsgBox Fix(-2.9) 'Returns: -2
    
    MsgBox Int(4.5) 'Returns: 4
    MsgBox Fix(4.5) 'Returns: 4
    
    MsgBox Int(-4.5) 'Returns: -5
    MsgBox Fix(-4.5) 'Returns: -4
    
    MsgBox Int(0.424) 'Returns: 0
    MsgBox Fix(0.424) 'Returns: 0
    
    MsgBox Int("13") 'Returns: 13
    MsgBox Fix("13") 'Returns: 13
    
    MsgBox Int("-4.5") 'Returns: -5
    MsgBox Fix("-4.5") 'Returns: -4
    
    MsgBox Int(True) 'Returns: -1
    MsgBox Fix(True) 'Returns: -1
    
    MsgBox Int(False) 'Returns: 0
    MsgBox Fix(False) 'Returns: 0
    
End Sub