Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 26th, 2006, 9:27 PM   #1
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
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'
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Aug 26th, 2006, 9:32 PM   #2
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 310
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
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.
andro is offline   Reply With Quote
Old Aug 26th, 2006, 9:46 PM   #3
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Ok thanks. Can I make the double and then put that double in the TextBox?
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Aug 26th, 2006, 9:59 PM   #4
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
ok i learned that what i just asked won't work.
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Aug 26th, 2006, 9:59 PM   #5
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
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.
Booooze is offline   Reply With Quote
Old Aug 26th, 2006, 11:51 PM   #6
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
yep thats what i did
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Aug 28th, 2006, 7:29 AM   #7
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
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 ?
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Aug 28th, 2006, 8:54 AM   #8
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
string x = "123";
double y = Convert.ToDouble(x);
txtResult.Text = Convert.ToString(y);
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 28th, 2006, 9:04 AM   #9
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0 King is an unknown quantity at this point
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.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Nov 7th, 2006, 5:16 AM   #10
milot
Programmer
 
milot's Avatar
 
Join Date: Nov 2006
Location: Kosovė/Prishtinė
Posts: 47
Rep Power: 0 milot is on a distinguished road
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));
milot is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Problem Associated with Vector Source code buggytoast Java 3 Apr 2nd, 2006 5:41 AM
Array issues :( Alo Tsum Java 10 Nov 26th, 2005 5:45 PM
help out beginner with some errors (solved) monka Java 8 Mar 3rd, 2005 8:50 PM
Y for yes and N for no problem sobank C++ 4 Mar 1st, 2005 10:33 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:17 AM.

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