How to convert string to single???

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
 
F

Fabio

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)
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top