Conversion.Int Method

Definition

Returns the integer portion of a number.

Overloads

Int(Decimal)

Returns the integer portion of a number.

Int(Double)

Returns the integer portion of a number.

Int(Int16)

Returns the integer portion of a number.

Int(Int32)

Returns the integer portion of a number.

Int(Int64)

Returns the integer portion of a number.

Int(Object)

Returns the integer portion of a number.

Int(Single)

Returns the integer portion of a number.

Int(Decimal)

Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

Returns the integer portion of a number.

C#
public static decimal Int(decimal Number);

Parameters

Number
Decimal

Required. A number of type Decimal or any valid numeric expression.

Returns

The integer portion of a number.

Exceptions

Number is not specified.

Number is not a numeric type.

Examples

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:

VB
' This code requires Option Strict Off
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:

VB
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:

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

For more information on CInt, see Type Conversion Functions.

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)).

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Int(Double)

Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

Returns the integer portion of a number.

C#
public static double Int(double Number);

Parameters

Number
Double

Required. A number of type Double or any valid numeric expression.

Returns

The integer portion of a number.

Exceptions

Number is not specified.

Number is not a numeric type.

Examples

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:

VB
' This code requires Option Strict Off
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:

VB
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:

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

For more information on CInt, see Type Conversion Functions.

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)).

Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the Int method to the any of the integral conversion functions, or if the Double value returned by Int is automatically converted to an integer with Option Strict set to Off. This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. The following example illustrates such an optimized conversion:

VB
Dim dbl As Double = 175.7619
Dim i3 As Integer = CInt(Int(dbl))         ' Result: 175

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Int(Int16)

Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

Returns the integer portion of a number.

C#
public static short Int(short Number);

Parameters

Number
Int16

Required. A number of type Short or any valid numeric expression.

Returns

The integer portion of a number.

Exceptions

Number is not specified.

Number is not a numeric type.

Examples

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:

VB
' This code requires Option Strict Off
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:

VB
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:

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

For more information on CInt, see Type Conversion Functions.

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)).

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Int(Int32)

Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

Returns the integer portion of a number.

C#
public static int Int(int Number);

Parameters

Number
Int32

Required. A number of type Integer or any valid numeric expression.

Returns

The integer portion of a number.

Exceptions

Number is not specified.

Number is not a numeric type.

Examples

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:

VB
' This code requires Option Strict Off
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:

VB
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:

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

For more information on CInt, see Type Conversion Functions.

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)).

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Int(Int64)

Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

Returns the integer portion of a number.

C#
public static long Int(long Number);

Parameters

Number
Int64

Required. A number of type Long or any valid numeric expression.

Returns

The integer portion of a number.

Exceptions

Number is not specified.

Number is not a numeric type.

Examples

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:

VB
' This code requires Option Strict Off
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:

VB
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:

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

For more information on CInt, see Type Conversion Functions.

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)).

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Int(Object)

Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

Returns the integer portion of a number.

C#
public static object Int(object Number);

Parameters

Number
Object

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

Returns

The integer portion of a number.

Exceptions

Number is not specified.

Number is not a numeric type.

Examples

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:

VB
' This code requires Option Strict Off
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:

VB
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:

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

For more information on CInt, see Type Conversion Functions.

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)).

Starting with Visual Basic 15.8, if the Number argument is an object whose runtime type is Double or Single, the performance of floating-point-to-integer conversion is optimized if you pass the value returned by the Int method to the any of the integral conversion functions, or if the value returned by Int is automatically converted to an integer with Option Strict set to Off. This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. For example:

VB
Dim d As Object = 173.7619
Dim i1 As Integer = CInt(Int(d))           ' Result: 173
Dim s As Object = 173.7619F
Dim i2 As Integer = CInt(Int(s))           ' Result: 173

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Int(Single)

Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

Returns the integer portion of a number.

C#
public static float Int(float Number);

Parameters

Number
Single

Required. A number of type Single or any valid numeric expression.

Returns

The integer portion of a number.

Exceptions

Number is not specified.

Number is not a numeric type.

Examples

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:

VB
' This code requires Option Strict Off
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:

VB
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:

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

For more information on CInt, see Type Conversion Functions.

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)).

Starting with Visual Basic 15.8, the performance of Single-to-integer conversion is optimized if you pass the value returned by the Int method to the any of the integral conversion functions, or if the Single value returned by Int is automatically converted to an integer with Option Strict set to Off. This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. The following example illustrates such an optimized conversion:

VB
Dim sng As Single = 175.7619
Dim i3 As Integer = CInt(Fix(sng))         ' Result: 175

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1