convert a string to Vb.net - Convert.toDouble

Asked

Viewed 597 times

3

I’m trying to convert a string in double Vb.net:

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

I’m getting the following amount -421942339 What I’m doing wrong?

  • Can you translate the question to English please?

  • I am trying to convert a string to double in Vb.net: Dim result as double dim Valuestring as string = -42.1942339 result = Convert.Todouble(Valuestring) Console.Writeline(result) I am receiving the following value -421942339 What I’m doing wrong?

1 answer

1

The problem is the culture being used to make the conversion. Probably, your operating system is configured for a culture that does not consider the point (i.e. .) as decimal separator.

To make the conversion, in this case you cannot let the method Convert.ToDouble use the standard operating system culture.

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

Convert.ToDouble(ValueString, CultureInfo.InvariantCulture);
  • CultureInfo.InvariantCulture: is a culture that does not vary with time. The decimal point is always ..
  • Living and learning. Thank you very much. Just to leave registered you need to import also -> Imports System.Globalization. Thanks

  • Consider accepting this answer if you have solved the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.