Convert from double to string

  • Thread starter Thread starter Marty
  • Start date Start date
M

Marty

Hi,

If I don't know that my (or any) windows 2k regional setting for the
decimal symbol is the dot (".") and I want to do this:

1- Dim dblOutput As Double
2- Dim strInput As String
3- strInput = "123,8"
4- dblOutput = Convert.ToDouble(strInput)

How can I avoid an error at line four ? And get it converted to double
to have this output : 123.8

Thanks a lot!

Marty
 
Marty,

Maybe you can use this,

If
System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.CurrencyDecim
alSeparator = "," Then
I hope this helps?

Cor
 
* Marty said:
If I don't know that my (or any) windows 2k regional setting for the
decimal symbol is the dot (".") and I want to do this:


1- Dim dblOutput As Double
2- Dim strInput As String
3- strInput = "123,8"
4- dblOutput = Convert.ToDouble(strInput)

How can I avoid an error at line four ? And get it converted to
double to have this output : 123.8

I suggest to store the values formatted in the invariant culture (this
culture uses "." instead of ",") and then parse the number using this
culture:

\\\
Dim d As Double = 22.34234
Dim s As String = d.ToString(System.Globalization.CultureInfo.InvariantCulture)
MsgBox(s)
d = Double.Parse(s, System.Globalization.CultureInfo.InvariantCulture)
MsgBox(d.ToString())
///
 
Does it mean that if the user write in the textbox "123,8", this
invariant culture could replace the "," by a "." ?

Marty
 
* Marty said:
Does it mean that if the user write in the textbox "123,8", this
invariant culture could replace the "," by a "." ?

No. I was referring to values that are stored in a file, for example.
If the user types in "12,123", on an en-US system 'Double.Parse' will
return 12,123.0 whereas on an de-DE system it would return 12.123.
 
Back
Top