diff --git a/src/DbfDataReader/DbfRecord.cs b/src/DbfDataReader/DbfRecord.cs index d6288eb..6b2f921 100644 --- a/src/DbfDataReader/DbfRecord.cs +++ b/src/DbfDataReader/DbfRecord.cs @@ -14,8 +14,18 @@ public class DbfRecord private readonly int _recordLength; private readonly byte[] _buffer; - public DbfRecord(DbfTable dbfTable) + private readonly DbfRecordConfiguration Config; + + public DbfRecord(DbfTable dbfTable, DbfRecordConfiguration config = null) { + if (config == null) + { + this.Config = DbfRecordConfiguration.GetDefault(); + } + else { + this.Config = config; + } + _encoding = dbfTable.CurrentEncoding; _recordLength = dbfTable.Header.RecordLength; _buffer = new byte[_recordLength]; @@ -55,7 +65,13 @@ private IDbfValue CreateDbfValue(DbfColumn dbfColumn, DbfMemo memo) value = new DbfValueLong(dbfColumn.Start, dbfColumn.Length); break; case DbfColumnType.Float: - value = new DbfValueFloat(dbfColumn.Start, dbfColumn.Length, dbfColumn.DecimalCount); + if (this.Config.ReadFloatsAsDecimals) + { + value = new DbfValueDecimal(dbfColumn.Start, dbfColumn.Length, dbfColumn.DecimalCount); + } + else { + value = new DbfValueFloat(dbfColumn.Start, dbfColumn.Length, dbfColumn.DecimalCount); + } break; case DbfColumnType.Currency: value = new DbfValueCurrency(dbfColumn.Start, dbfColumn.Length, dbfColumn.DecimalCount); diff --git a/src/DbfDataReader/DbfRecordConfiguration.cs b/src/DbfDataReader/DbfRecordConfiguration.cs new file mode 100644 index 0000000..b2ee36b --- /dev/null +++ b/src/DbfDataReader/DbfRecordConfiguration.cs @@ -0,0 +1,25 @@ +namespace DbfDataReader +{ + /// + /// Class DbfRecordConfiguration provides a configuration for the DbfRecord class + /// + public class DbfRecordConfiguration + { + /// + /// Configuation that denotes floats from the database should be read as decimal in C#. + /// This is to mitigate precision issues where a number in the database is labeled as a float, but is greater than the size of a float in C# + /// + public bool ReadFloatsAsDecimals { get; set; } + + /// + /// Provides a default configuration + /// + /// A DbfRecordConfigration object containing the default configuration + public static DbfRecordConfiguration GetDefault() + { + return new DbfRecordConfiguration { + ReadFloatsAsDecimals = false + }; + } + } +}