static void Main()
{
Console.Write("Please input a number: ");
Console.WriteLine("\n The number you selected was {0} \n", method());
}
static int method()
{
int var = int.Parse(Console.ReadLine());
return var;
}
The above code throws a format exception. I tried storing the input in a string variable and then parsing, but it had the same problem. I also tried using the Convert class and still had the same problem. I would appreciate if someone could show me where I am wrong.
I am trying to convert 23.4, for example. (It works for Natural numbers but why not 4345.5, for example)
floatpart but you can return only the integer part. 3.6 becomes 3, for example.(int)numberto get an integer where the decimal part is simply truncated. If you want that it gets rounded useMath.Roundfirst.