![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
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'
__________________
|
|
|
|
|
|
#2 |
|
Professional Programmer
|
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. |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Ok thanks. Can I make the double and then put that double in the TextBox?
__________________
|
|
|
|
|
|
#4 |
|
Expert Programmer
|
ok i learned that what i just asked won't work.
__________________
|
|
|
|
|
|
#5 | |
|
Expert Programmer
|
Quote:
|
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
yep thats what i did
__________________
|
|
|
|
|
|
#7 | |
|
Professional Programmer
|
Quote:
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 ! |
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0
![]() |
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! |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Nov 2006
Location: Kosovė/Prishtinė
Posts: 47
Rep Power: 0
![]() |
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)); |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |