473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 39058


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nathan | last post by:
Is there a way to convert a string to a CipherMessage? I am calling a function that decrypts a CipherMessage and returns the value. The only problem is when I want to use an encrypted value stored...
6
by: Sandy | last post by:
I'm building a SQL String and I want to choose only the records that are part of the current contractID. My Variable Dim contrID = Request.Params("oId" I put it into the SQL String WHERE ...
6
by: | last post by:
How do I convert a single character, e.g. "a" into char for use in the 'split' command? p.s. I have option strict on Tia.
3
by: Petr Jakes | last post by:
Hi, I am trying to convert string to the "escaped string". example: from "0xf" I need "\0xf" I am able to do it like: a="0xf" escaped_a=("\%s" % a ).decode("string_escape") But it looks a...
3
by: Ursula | last post by:
Is it possible to convert a string in a file. The problem is this: I have an object string that is a file xml and I want to pass to Deserialize function, but Deserialize function expect an object...
3
by: Shawn Ferguson | last post by:
Hello All, I'm trying to do what I would think would be simple and straightforward, but it is not. I have a 2 textbox on a form, a label, and a button, when I click the botton I want to add the...
4
by: Man4ish | last post by:
HI , I am trying to convert string into char array of characters.but facing problem. #include <iostream> #include <string> using namespace std; int main() { string t="1,2,3,4,5,6";
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
9
by: engteng | last post by:
How do I convert string to numeric in VB.NET 2003 ? Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle then not convert. Regards, Tee
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.