By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,727 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,727 IT Pros & Developers. It's quick & easy.

How to convert string to single???

P: n/a
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
Jul 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a


Hi Jalmari

use this ...

My_single = Convert.ToSingle(My_string)

John

"JH-PRO" <jhpro2000@REM_THIS_hotmail.comwrote in message
news:46**********************@news.fv.fi...
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

Jul 24 '07 #2

P: n/a
"JH-PRO" <jhpro2000@REM_THIS_hotmail.comha scritto nel messaggio
news:46**********************@news.fv.fi...
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.InvariantInf o)

--
Help The New .Net Site! http://www.devbox4.net
Jul 24 '07 #3

P: n/a
JH-PRO wrote:
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

--
Göran Andersson
_____
http://www.guffa.com
Jul 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.