I'm having some issues while inserting a double for example: 4.8. The program does not want to read it. As you can see in the screenshot.
Asked
Active
Viewed 72 times
0
-
2Hi, please add your code as text to your question. You can use [edit] to [edit] your question. – Stefan Oct 04 '20 at 15:03
-
2The error says your input is not understood. Can you show us what you have typed? – Stefan Oct 04 '20 at 15:04
-
3Probably your culture use "," for decimals, see this: https://stackoverflow.com/questions/28673269/why-double-parse-throws-formatexception-only-through-rdp – Omar Piga Oct 04 '20 at 15:05
-
It throws an error even in the most simple codes: using System; namespace SoftUni { class Program { static void Main(string[] args) { double income = double.Parse(Console.ReadLine()); Console.WriteLine(income); } } } – Chavi Oct 04 '20 at 15:15
-
Found the issue. It came from the regional settings on my Windows. It was set to use "," instead of "." so every time I used ".", the error came. – Chavi Mar 29 '21 at 07:02
2 Answers
3
The problem might be your cultural setting. Probably expected comma instead of a point. Try this:
double income = double.Parse(Console.ReadLine(), NumberStyles.Any, CultureInfo.InvariantCulture);

smolchanovsky
- 1,775
- 2
- 15
- 29
0
double income;
// In case you need style and culture
style = NumberStyles.Number | NumberStyles.AllowCurrencySymbol;
culture = CultureInfo.CreateSpecificCulture("en-GB");
// Keep on reading until you make it
while(!double.TryParse(Console.ReadLine(), style, culture, out income));

Athanasios Kataras
- 25,191
- 4
- 32
- 61