0

Converting Negative Numbers (C#)

Do anyone know how to convert also Negative Numbers from your input? For example you used " name = Convert.ToInt32(Console.ReadLine); " then after run the code if you wrote Negative Number you get an Error Compilation.

23rd Mar 2019, 6:50 AM
Foxyg3n
Foxyg3n - avatar
4 Réponses
+ 1
1. It's Console.ReadLine() not Console.ReadLine 2. Convert.ToInt32() can convert negative integer too. 3. If your number is negative non-integer, use Convert.ToDouble() instead.
23rd Mar 2019, 7:08 AM
Gordon
Gordon - avatar
+ 1
Yes smart keyboard sometimes bring inconvenience in coding. For example it will keep helping us to correct our "spelling mistakes" into "Console. Write Line" 🤷‍♂️
23rd Mar 2019, 7:53 AM
Gordon
Gordon - avatar
0
1. Mistakes happens. 2. I don't think it can't, i just think it's because of the ReadLine command. Like it interpret "-" wrong but im only guessing. 3. Thanks, I'll just try your way. (;
23rd Mar 2019, 7:26 AM
Foxyg3n
Foxyg3n - avatar
0
Ok, you know... I'm stupid. Convert. ToInt32 actually works but my awsome keyboard makes space after "-" so it looks like "- 3" Sorry to bother...
23rd Mar 2019, 7:40 AM
Foxyg3n
Foxyg3n - avatar