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

parse numeric fields with fractional parts #21

Open
chumpa opened this issue Jan 26, 2016 · 0 comments
Open

parse numeric fields with fractional parts #21

chumpa opened this issue Jan 26, 2016 · 0 comments

Comments

@chumpa
Copy link

chumpa commented Jan 26, 2016

Enhancement: to parse fractional parts.

my dirty hack is:

public BigDecimal getBigDecimal(String fieldName) {
    DbfField f = getField(fieldName);
    String s = getString(fieldName);

    if (s == null || s.trim().length() == 0) {
        return null;
    } else {
        s = s.trim();
    }

    if (s.contains(NUMERIC_OVERFLOW)) {
        return null;
    }

    int a = f.getNumberOfDecimalPlaces();
    if (a==0)
        return new BigDecimal(s);
    else {
        s = s.replace(',', '.');
        MathContext mc = new MathContext(a);
        return new BigDecimal(s, mc);
    }
}
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

No branches or pull requests

1 participant