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

VB.Net program to demonstrate the CDbl() function

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

The CDbl() function is used to convert the value of different data types to the double type.

Syntax :

CDbl(val)

Parameters :

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

Return Value :

The CDbl() function returns a double converted number.

Program :

Below is the source code for demonstrating the CDbl() function. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim num As Double = 0
        Dim n1 As Single = 10.25
        Dim n2 As Integer = 12
        Dim n3 As Decimal = 25.35
        Dim n4 As String = "122"
        num = CDbl(n1)
        Console.WriteLine("Double Number: {0}", num)
        num = CDbl(n2)
        Console.WriteLine("Double Number: {0}", num)
        num = CDbl(n3)
        Console.WriteLine("Double Number: {0}", num)
        num = CDbl(n4)
        Console.WriteLine("Double Number: {0}", num)
    End Sub
End Module
	
Output:
Double Number: 10.25
Double Number: 12
Double Number: 25.35
Double Number: 122

Explanation:

We created a Module1 module in the above program, which contains the Main() method. Five variables num, n1, n2, n3, and n4 have been created in the Main() method and are initialized with 0, 10.25, 12, 25.35, and 122.

num = CDbl(n1)
Console.WriteLine("Double Number: {0}", num)

num = CDbl(n2)
Console.WriteLine("Double Number: {0}", num)

num = CDbl(n3)
Console.WriteLine("Double Number: {0}", num)

num = CDbl(n4)
Console.WriteLine("Double Number: {0}", num)

We have converted the value of the specified variables into double numbers in the above code and printed them on the screen of the console.