convert a string to vb.net - convert.toDouble

3

I'm trying to convert a string to double into vb.net:

 Dim result as double
 Dim ValueString as string = "-42.1942339"
 result = Convert.ToDouble(ValueString)
 Console.WriteLine(result)

I'm getting the following value -421942339 What am I doing wrong?

    
asked by anonymous 06.04.2015 / 09:02

1 answer

1

The problem is the culture being used to do the conversion. Your operating system is probably configured for a culture that does not consider the dot (i.e. . ) as the decimal separator.

In order to do the conversion, you will not be able to let the Convert.ToDouble method use the default culture of the operating system.

For this it is possible to pass a parameter to the Convert.ToDouble method indicating the culture:

Convert.ToDouble(ValueString, CultureInfo.InvariantCulture);
  • CultureInfo.InvariantCulture : is a culture that does not change over time. The decimal point is always . .
06.04.2015 / 11:35