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)
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.
Conversion of Strings to Numbers You can use the Val function to explicitly convert the digits in a string to a number.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With