How to convert string to single???

  • Thread starter Thread starter JH-PRO
  • Start date Start date
J

JH-PRO

Please help!

How to convert string to single

Here my start values:

Dim My_string as string = "29.02"
Dim My_single as single = 0.0


i try this way but i get error

My_single = CSng(My_string )


Conversion from string "29.02" to type 'Single' is not valid.

Thanx

Jalmari
 
JH-PRO said:
Please help!

How to convert string to single

Here my start values:

Dim My_string as string = "29.02"
Dim My_single as single = 0.0


i try this way but i get error

My_single = CSng(My_string )


Conversion from string "29.02" to type 'Single' is not valid.

This may be done by your decimal separator defined in the control panel that
is not a ".".

Use this:

My_single = Single.Parse(My_string,
System.Globalization.NumberFormatInfo.InvariantInfo)
 
JH-PRO said:
Please help!

How to convert string to single

Here my start values:

Dim My_string as string = "29.02"
Dim My_single as single = 0.0


i try this way but i get error

My_single = CSng(My_string )


Conversion from string "29.02" to type 'Single' is not valid.

Thanx

Jalmari

There is no conversion directly from a string to a single, as a string
is not a numeric type. What you have to do is to parse the string. There
are some different methods for that.

This will just parse the string, and gives an exception if it can't:

My_single = Single.Parse(My_string)

This will try to parse the string, and gives you the opportunity to
handle the situation if it can't be parsed:

If Single.TryParse(My_string, My_single) Then
' ok; My_single contains the value
Else
' could not be parsed
End If
 
Back
Top