|
-
Nov 27th, 2003, 04:16 AM
#1
Console.ReadLine() --> double variable
How do I get the user's number into the double?
Code:
string temp;
double myDBL;
Console.Write("Enter a number: ");
temp = Console.ReadLine(); //something like "231.44324"
//perform some tests on the string to make sure its ok
//...
myDBL= temp; //causes compiler cast error
Error: Cannot convert type 'string' to 'double'
I don't live here any more.
-
Nov 27th, 2003, 05:48 AM
#2
Hyperactive Member
Here you go:
Code:
myDBL= Double.Parse(temp);
That should work.
HTH,
Stephan
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Nov 27th, 2003, 08:48 AM
#3
OK thanks, is that the normal way to do it?
I don't live here any more.
-
Nov 27th, 2003, 01:57 PM
#4
Lively Member
Don't bother with the checking part, just cast it and catch exceptions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|