![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 3
![]() |
I think he think he is using VB.NET because it automatically does the conversion
|
|
|
|
|
|
#12 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5
![]() |
I prefer using the Parse() or TryParse() methods instead- the former is more appropriate if you know the number is okay to convert, while the latter is better for any 'un-vetted' input (particularly user input).
Parse() returns the converted value if it was successful, or otherwise throws an exception. TryParse() returns a bool that is true on success, and fills in the value via an out parameter. Example: double int value;
bool success;
value = double.Parse("123.45"); // this line will be okay
value = double.Parse("abc.de"); // throws exception
success = double.TryParse("123.45", out value); // returns true, value is filled in
success = double.TryParse("abc.de", out value); // returns false, value is unchanged[edit2] Well, I didn't read the thread all the way through, and failed to notice the problem was actually converting the other way around. So yeah, ToString() as several people mentioned works for that (and will work on every single type, although you might not always get the text you expect). [/edit2]
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
![]() |
| 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 |