I need to convert a string with the following format -0.0092 to a number type with which I can operate later, I have tried with Val, or CdBl and both lose the sign or truncate the final result ...
I need to convert a string with the following format -0.0092 to a number type with which I can operate later, I have tried with Val, or CdBl and both lose the sign or truncate the final result ...
You can use Double.Parse
for example:
Double.Parse("-0.0092")
But you may find yourself with an unexpected result, since in our culture the decimal point is usually considered to be ,
, not .
.
In that case, the safest thing is the following, use InvariantCulture
in which the decimal point is the .
:
Dim numdbl As Double = Double.Parse("-0.0092", Globalization.CultureInfo.InvariantCulture)