Search code examples
c#csvformatexceptionmathnet-numerics

Math.Net Numerics DelimitedReader.Read Format Exception


I am porting my MATLAB application to C# and decided to use Math.NET Numerics for it, but I am encountering the following problem: When I try to use delimited reader to load my csv into Matrix<double> data,

data = DelimitedReader.Read<double>(ofile.FileName, false, ",", true);

I am getting format exception; ofile.FileName is correct and my csv looks like this:

enter image description here

I searched for reasons, but didn't find the solution. Hopefully you will be able to help me, thank you in advance.

Kind regards.

EDIT1: providing csv as requested in comments unixdates.csv


Solution

  • When c# tries to parse a float, it uses the decimal separator of the current system language. You're probably running under a language that uses a comma as the decimal separator, instead of the dot.

    You can specify which format to use, though.

    data = DelimitedReader.Read<double>(ofile.FileName, false, ",", true, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);