jeudi 2 avril 2015

Convert decimal numbers from string to double

I have read a file containnig numbers including decimal ones e.g.: 10.4 into an array of strings. I want to obtain an array of doubles. My method work for numbers without the decimal part only, but for decimal ones gives following error:



An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format.



Would you have some ideas how to modify the code to work for all positive real numbers?



string[] lines = System.IO.File.ReadAllLines(fd.FileName);
numbers_input = lines.Select(x => double.Parse(x)).ToArray();

Aucun commentaire:

Enregistrer un commentaire