Convert.ToDouble(string); x1,x2,y1,y2,u1,u2,v1,v2;
i need some help converting from a string to an integer /double...i have a test to do tomorrow andi just started learnin c# yesterday
visual c# basicsconversion
Page 1 of 1
5 Replies - 785 Views - Last Post: 28 September 2009 - 03:40 PM
Replies To: visual c# basics
#2
Re: visual c# basics
Posted 28 September 2009 - 03:33 PM
We do not do your work for you. Read our rules and come back.
#3
Re: visual c# basics
Posted 28 September 2009 - 03:33 PM
What exactly is x1, x2 etc for.
You have the correct code at the top although the syntax seems a bit strange:
EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.
You have the correct code at the top although the syntax seems a bit strange:
double myNewDouble = Convert.ToDouble(string_to_convert_goes_here); int myNewInt = Convert.ToInt32(string_to_convert_goes_here);
EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.
This post has been edited by danny_kay1710: 28 September 2009 - 03:35 PM
#4
Re: visual c# basics
Posted 28 September 2009 - 03:39 PM
Smurphy, on 28 Sep, 2009 - 02:33 PM, said:
We do not do your work for you. Read our rules and come back.
i kno i just need to know how to convert from a string to an integer thats all
danny_kay1710, on 28 Sep, 2009 - 02:33 PM, said:
What exactly is x1, x2 etc for.
You have the correct code at the top although the syntax seems a bit strange:
EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.
You have the correct code at the top although the syntax seems a bit strange:
double myNewDouble = Convert.ToDouble(string_to_convert_goes_here); int myNewInt = Convert.ToInt32(string_to_convert_goes_here);
EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.
the x1 y1 stuff are all the things i have to convert to a double
reginaleo, on 28 Sep, 2009 - 02:37 PM, said:
Smurphy, on 28 Sep, 2009 - 02:33 PM, said:
We do not do your work for you. Read our rules and come back.
i kno i just need to know how to convert from a string to an integer thats all
danny_kay1710, on 28 Sep, 2009 - 02:33 PM, said:
What exactly is x1, x2 etc for.
You have the correct code at the top although the syntax seems a bit strange:
EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.
You have the correct code at the top although the syntax seems a bit strange:
double myNewDouble = Convert.ToDouble(string_to_convert_goes_here); int myNewInt = Convert.ToInt32(string_to_convert_goes_here);
EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.
the x1 y1 stuff are all the things i have to convert to a double
i guess i should have them where i have string written then...ok thank you
#5
Re: visual c# basics
Posted 28 September 2009 - 03:40 PM
reginaleo, on 28 Sep, 2009 - 09:35 PM, said:
DIC does have rules that state you have to make a best effort.
If you look at my first post which states you have put the correct code in your first post - plus with my slight reformat it should give you some hints on what you need to do. If x1, x2 etc where all the values you needed to change just letting you know you will need more than one line.
#6
Re: visual c# basics
Posted 28 September 2009 - 03:40 PM
You will need a variable of the type that you want to convert. Then you would pass in the string you want to convert as an argument. There are three ways to convert strings to numbers.
The first is the one you posted:
That would convert the string s to a double.
Next there is the Parse method of the types.
Both of those are equivalent in that Convert calls the Parse method.
The third is a little more complicated but is safer in that if you pass an invalid argument your program will not throw an exception.
If TryParse succeeds it returns true. If it fails it returns false. So you could check to make sure the conversion was successful.
Converting to an int is done the same way. You basically just change double to int
The first is the one you posted:
double value = Convert.ToDouble(s);
That would convert the string s to a double.
Next there is the Parse method of the types.
double value = double.Parse(s);
Both of those are equivalent in that Convert calls the Parse method.
The third is a little more complicated but is safer in that if you pass an invalid argument your program will not throw an exception.
double result = 0; bool conversionResult = double.TryParse(s, out result);
If TryParse succeeds it returns true. If it fails it returns false. So you could check to make sure the conversion was successful.
if (converstionResult) // Conversion worked! else // Conversion failed!
Converting to an int is done the same way. You basically just change double to int
int value = int.Parse(s); value = Convert.ToInt32(s); int result = 0; bool conversionResult = int.TryParse(s, out result);
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|