CsvReader icon indicating copy to clipboard operation
CsvReader copied to clipboard

Customizable CultureInfo

Open pepr opened this issue 6 years ago • 3 comments

Hello phatcher,

Firstly thanks for the nice tool.

Now, I am using the CsvReader for importing the data in the Czech environment, where CultureInfo prescribes using comma as a decimal separator. On the other hand, for CSV files, it is often the case when the data is internacional and it uses dot as the decimal separator.

I am having issues with reading a file with Decimal values with dot (described at https://stackoverflow.com/questions/53830123/lumenworks-csvreader-how-to-read-decimal-using-invariant-culture).

Peeking in the source, I have found the code like

        decimal IDataRecord.GetDecimal(int i)
        {
            ValidateDataReader(DataReaderValidations.IsInitialized | DataReaderValidations.IsNotClosed);
            return decimal.Parse(this[i], CultureInfo.CurrentCulture);
        }

Could the culture info be replaced by CultureInfo.InvariantCulture, or better (say), could it be replaced by a property that could be changed at the instance level?

Thanks and wishing you nice Christmas time and Happy new year. P.

pepr avatar Dec 18 '18 11:12 pepr

@pepr I'm open to a pull request with this in, I'll have a look but I'm not sure I can get to it myself.

phatcher avatar Dec 21 '18 11:12 phatcher

I had the same problem. I solved this by setting the current culture before reading the file, like so:

CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-BE");

fretje avatar Feb 26 '19 18:02 fretje

@fretje Looks like a documentation improvement then rather than a code change

phatcher avatar Feb 28 '19 10:02 phatcher