Home >>VB.Net Programs >VB.Net program to convert a double number into an integer number

VB.Net program to convert a double number into an integer number

How to convert a double number into an integer number in VB.Net

Using the Int() function, we can build a VB.Net program to convert a double number into an integer number.

Program

Below is the source code for converting a double number to an integer number. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim x As Double = 987654.321
        Dim y As Integer = 0
        
        'type conversion
        y = Int(x)
        
        Console.WriteLine("value of x: {0}", x)
        Console.WriteLine("value of y: {0}", y)
        
        'hit ENTER to exit the program
        Console.ReadLine()
    End Sub
End Module
	
Output:
value of x: 987654.321
value of y: 987654

Explanation:

Here, we created a module containing the method of Main(), here we created two local variables x and y, respectively initialized 987654.321 and 0.

y = Int(x)
Console.WriteLine("value of x: {0}", x)
Console.WriteLine("value of y: {0}", y)

Here using the Int() function, we have converted the value of double variable an into integer variable y. After that on the console screen, we printed the x and y values.


No Sidebar ads