Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read user input of double type

I have found this answered in other places using loops, but I wasn't sure if there is actually a function that I'm not finding that makes this easier, or if this is a possible (in my opinion) negative side to C#.

I'm trying to read in a double from user input like this:

Console.WriteLine("Please input your total salary: ") // i input 100
double totalSalary = Console.Read(); //reads in the 1, changes to 49.

I've found a couple other posts on this, and they all have different answers, and the questions asked aren't exactly the same either. If i just want the user input read in, what is the best way to do that?

like image 850
trueCamelType Avatar asked Dec 11 '12 03:12

trueCamelType


People also ask

How do you check if the input is a double Java?

parseDouble(stringInput); when you scan the input as a String you can then parse it to see if it is a double. But, if you wrap this static method call in a try-catch statement, then you can handle the situation where a double value is not parsed.

Which function takes double input from console?

The ToInt32() and ToDouble() method of Convert class converts the string input to integer and double type respectively. Similarly we can convert the input to other types.


1 Answers

Try this:

double Salary = Convert.ToDouble(Console.ReadLine());
like image 83
Dylan Avatar answered Sep 17 '22 13:09

Dylan