Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a configuration object for the DbfRecord class #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Dmbob
Copy link

@Dmbob Dmbob commented Sep 1, 2021

It is possible to run into issues where a value in a dbf file is has a type of Float, but is larger than a float in C#.

This would cause precision issues when the value is passed into the float.TryParse method.

See the below example:

var numberAsString = "123456.78";
float.TryParse(numberAsString, out var numberAsFloat); // numberAsFloat will be 123456.781 here

// Using ToString will round it back to 123456.78
Console.WriteLine(numberAsFloat.ToString());

It's worth noting that calling ToString on the float with no parameters would round to the nearest hundredth and coincidentally show the value as what it is supposed to be.

In order to mitigate this, a configuration class was created that can be passed into the DbfRecord class. This configuration currently contains one property (ReadFloatsAsDecimals) that will tell the CreateDbfValue method to use the DbfValueDecimal class for floats instead of the DbfValueFloat class.

The configuration that gets provided is an optional parameter on the DbfRecord class and provides a default configuration that matches the current expected behavior.

…figration to support reading floats as decimals from the database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant