iryndin / jdbf

Java utility to read/write DBF files
108 stars 77 forks source link

parse numeric fields with fractional parts #21

Open chumpa opened 8 years ago

chumpa commented 8 years ago

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);
    }
}