Reputation: 7
I need a console app that changes the sign to a certain typed number. You type 10, it gives you -10. And so on. I've managed to do that, but I can't do it if I type 1.5 for example. Or any decimal number. I get "Input string was not in a correct format". this is what I did.
string inputData = Console.ReadLine();
int a = Convert.ToInt32 (inputData);
int b = a * (-1);
Console.WriteLine(b);
Console.ReadLine();
Upvotes: 0
Views: 598
Reputation: 730
decimal
as a variable type if you want to work with decimal numbersConvert.ToDecimal
instead of ToInt32
-a
insteadstring inputData = Console.ReadLine();
decimal a = Convert.ToDecimal (inputData);
decimal b = -a;
Console.WriteLine(b);
Console.ReadLine();
Upvotes: 2