471,853 Members | 783 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

How to convert string to single???

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
3 38507


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
"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
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.

Similar topics

2 posts views Thread by Nathan | last post: by
3 posts views Thread by Petr Jakes | last post: by
3 posts views Thread by Ursula | last post: by
3 posts views Thread by Shawn Ferguson | last post: by
12 posts views Thread by Peter | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.