CDec Function in VB.NET

How to Convert String to Decimal in VB.Net?

Explanation

CDec Function - Convert String to Decimal

CDec Function in Visual Basic.net 2008 is used convert a string expression into decimal datatype. This function uses the locale settings of your system for conversion.
Syntax:

CDec(expression)
Example:

Module Module1
Sub Main()
Dim a As Integer = 13
Console.WriteLine("The decimal value of 13 divided by 2 is:"
& CDec(a / 2))
Console.ReadLine()
End Sub
End Module
Result:

The decimal value of 13 divided by 2 is: 6.5

In the above example, an integer expression '13/2' is converted to decimal datatype.

Visual Basic Tutorial


Ask Questions

Ask Question