TOP

VBA Functions: Int and Fix

Description

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


Int and Fix Syntax

Int(number)

Fix(number)

VBA Int and Fix example

Using the Int and Fix functions to convert different types of numeric values, which will also help you better understand their difference when working with negative values:

Sub IntFixExample()

      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