Fix Function
 Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

# Int, Fix Functions

Visual Studio .NET 2003

Return the integer portion of a number.

```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 }
```

#### Parameter

number
Required. A number of type Double or any valid numeric expression. If number contains Nothing, Nothing is returned.

#### Exceptions/Errors

Exception type Error number Condition
ArgumentNullException 5 Number is not specified.
ArgumentException 5 Number is not a numeric type.

#### Remarks

Both the Int and Fix functions remove the fractional part of number and return the resulting integer value.

The difference between Int and Fix functions is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

`Fix(number)` is equivalent to `Sign(number) * Int(Abs(number)).`

#### Example

This example illustrates how the Int and Fix functions return integer portions of numbers. In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number. The following example requires you to specify Option Strict Off because implicit conversions from type Double to type Integer are not allowed under Option Strict On:

```Option Strict Off
' Code will not function unless placed within a Sub or Function
Dim MyNumber As Integer
MyNumber = Int(99.8)   ' Returns 99.
MyNumber = Fix(99.8)   ' Returns 99.

MyNumber = Int(-99.8)   ' Returns -100.
MyNumber = Fix(-99.8)   ' Returns -99.

MyNumber = Int(-99.2)   ' Returns -100.
MyNumber = Fix(-99.2)   ' Returns -99.
```

You can use the CInt function to explicitly convert other data types to type Integer with Option Strict Off. However, Cint rounds to the nearest integer instead of truncating the fractional part of numbers. For example:

```MyNumber = CInt(99.8)    ' Returns 100.
MyNumber = CInt(-99.8)   ' Returns -100.
MyNumber = CInt(-99.2)   ' Returns -99.
```

You can use the CInt function on the result of a call to Fix or Int to perform explicit conversion to integer without rounding. For example:

```MyNumber = CInt(Fix(99.8))   ' Returns 99.
MyNumber = CInt(Int(99.8))   ' Returns 99.
```

#### Requirements

Namespace: Microsoft.VisualBasic

Module: Conversion

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)