Convert a string to a signed number

0

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 ...

    
asked by marcss 04.10.2018 в 11:16
source

1 answer

3

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)
    
answered by 04.10.2018 / 11:25
source