Skip to main content

Convert to Integer

In This Article

Rounds the value of an expression under cursor to an integer, using a call to one of the following methods, and generates an integer type-cast expression.

Method Description
Math.Ceiling() Rounds the expression value to the smallest integer greater than or equal to this value.
Math.Floor() Rounds the expression value to the largest integer less than or equal to this value.
Math.Round() Rounds the expression value to the nearest integer.

#Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on an expression of decimal, Single, double, or float type.

Note

The code provider is available in Visual Basic code, if the Strict compiler option is on.

#Example

private int TestMethod(double param1)
{
    return param1;
}
Option Strict On
Public Class ConvertToInteger
    Private Function TestMethod(ByVal param1 As Double) As Integer
        Return param1
    End Function
End Class

Result:

private int TestMethod(double param1)
{
    return (int)Math.Floor(param1);
}
Option Strict On
Public Class ConvertToInteger
    Private Function TestMethod(ByVal param1 As Double) As Integer
        Return CInt(Math.Floor(param1))
    End Function
End Class