Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the CInt() function

VB.Net program to demonstrate the CInt() function

Write a VB.Net program to demonstrate the CInt() function

The function CInt() is used to convert the value of various data types to an integer type.

Syntax :

CInt(val)

Parameters :

  • val: It may be a variable with different types of data.

Return Value :

A converted integer number will be returned by the CInt() function.

Program :

Below is the source code to demonstrate the CInt() function. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim num As Integer = 0
        Dim n1 As Double = 10.25
        Dim n2 As Single = 12.25
        Dim n3 As Byte = 25
        Dim n4 As String = "223"
        num = CInt(n1)
        Console.WriteLine("Integer Number: {0}", num)
        num = CInt(n2)
        Console.WriteLine("Integer Number: {0}", num)
        num = CInt(n3)
        Console.WriteLine("Integer Number: {0}", num)
        num = CInt(n4)
        Console.WriteLine("Integer Number: {0}", num)
    End Sub
End Module
	
Output:
Integer Number: 10
Integer Number: 12
Integer Number: 25
Integer Number: 223

Explanation:

We created a Module1 module in the program above that contains the Main() method. Five variables num, n1, n2, n3, and n4 were created in the Main() method, initialized with 0, 10.25, 12.25, 25, and 223.

num = CInt(n1)
Console.WriteLine("Integer Number: {0}", num)

num = CInt(n2)
Console.WriteLine("Integer Number: {0}", num)

num = CInt(n3)
Console.WriteLine("Integer Number: {0}", num)

num = CInt(n4)
Console.WriteLine("Integer Number: {0}", num)

Here, the value of the specified variable is converted to an integer and printed on the console screen.