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

Here, we are going to learn how to convert a double number into an integer number in VB.Net?
Submitted by Nidhi, on November 26, 2020 [Last updated : February 18, 2023]

Converting a double number into an integer number

We will create a program in VB.Net to convert a double number into an integer number using Int() function.

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

The source code to convert a double number into an integer number is given below. The given program is compiled and executed successfully.

'VB.Net program to convert a double number 
'to integer number.

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

Output:

value of a: 123456.789
value of b: 123456

Explanation:

Here, we created a Module that contains the Main() method, here we created two local variables a and b that is initialized 123456.789 and 0 respectively.

b = Int(a)

Console.WriteLine("value of a: {0}", a)
Console.WriteLine("value of b: {0}", b)

Here, we converted the value double variable a into integer variable b using the Int() function. After that, we printed the value of a and b on the console screen.

VB.Net Basic Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.