Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   String to double (http://www.programmingforums.org/showthread.php?t=11186)

crawforddavid2006 Aug 26th, 2006 10:27 PM

String to double
 
I know i ask this in a lot of different areas but its only because I have no idea how to do it. How do I change a string into a double. I tried the following to change a string into an int but it does not work.
[PHP]
string myStr = "123"
displayBox.text = Convert.ToInt32(myStr);[/PHP]

The error that i get is this
:

Cannot implicity convert 'int' to 'string'

andro Aug 26th, 2006 10:32 PM

Convert.ToDouble()

The reason you got an error is because displayBox.text is a String, and you are assigning an int to a string. Your conversion worked fine.

crawforddavid2006 Aug 26th, 2006 10:46 PM

Ok thanks. Can I make the double and then put that double in the TextBox?

crawforddavid2006 Aug 26th, 2006 10:59 PM

ok i learned that what i just asked won't work.

Booooze Aug 26th, 2006 10:59 PM

Quote:

Originally Posted by crawforddavid2006
Ok thanks. Can I make the double and then put that double in the TextBox?

If you convert the double to a string, yes.

crawforddavid2006 Aug 27th, 2006 12:51 AM

yep thats what i did

xavier Aug 28th, 2006 8:29 AM

Quote:

Originally Posted by crawforddavid2006
I know i ask this in a lot of different areas but its only because I have no idea how to do it. How do I change a string into a double. I tried the following to change a string into an int but it does not work.
[PHP]
string myStr = "123"
displayBox.text = Convert.ToInt32(myStr);[/PHP]

The error that i get is this
:

Cannot implicity convert 'int' to 'string'

:

Cannot implicity convert 'int' to 'string'

The thing is that you're probably trying to put that into a textBox. So the ToInt32 worked fine , but you have to use : ToString() on it like so :
:

displayBox.text = Convert.ToInt32(myStr).ToString();

What exactly are you trying to do ?

Infinite Recursion Aug 28th, 2006 9:54 AM

:

string x = "123";
double y = Convert.ToDouble(x);
txtResult.Text = Convert.ToString(y);


King Aug 28th, 2006 10:04 AM

crawforddavid2006, don't take this the wrong way man, but you really need to learn how to do a bit of research. This could have been found on Google with about 10 mins of searching. Maybe pick up a C# book if you have a good amount of interest in it.

milot Nov 7th, 2006 6:16 AM

After all those replies i guess that crawforddavid2006 solved the problem, but I am posting another way to do it (one-line way of the snippet submitted by Infinite Recursion):

:

string str = "123";
textBox1.Text = Convert.ToString(Convert.ToDouble(str));



All times are GMT -5. The time now is 12:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC