Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a string to decimal in VB.NET

What will be the easiest way to convert a string to decimal?

Input:

a = 40000.00-

Output will be

40,000.00-

I tried to use this code:

Dim a as string

a = "4000.00-"

a = Format$(a, "#,###.##")
console.writeline (a)
like image 434
user709787 Avatar asked May 19 '11 08:05

user709787


People also ask

How do you convert a string to a decimal?

Converting a string to a decimal value or decimal equivalent can be done using the Decimal. TryParse() method. It converts the string representation of a number to its decimal equivalent. When a value is returned by this method, the conversion was successful.

How do I convert a string to a number in Visual Basic?

Conversion of Strings to Numbers You can use the Val function to explicitly convert the digits in a string to a number.

How do I convert a string to an int?

Use Integer.parseInt() to Convert a String to an Integer This method returns the string as a primitive type int. If the string does not contain a valid integer then it will throw a NumberFormatException.


1 Answers

For VB.NET:

CDec(Val(string_value))

For example,

CDec(Val(a))

The result will be 40000D or if the value for a = "400.02" then it will be 400.02D.

like image 146
Rohit Avatar answered Oct 09 '22 20:10

Rohit