iryndin / jdbf

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

Problem reading Double solved #46

Open hermobass opened 6 years ago

hermobass commented 6 years ago

Hi, First of all, thank you to iryndin for sharing his great work.

I was having problem reading Double values from a dbf, so I solved it adding this in "DbfRecord.java":

At toMap() method, I have added the following case:

case Double: map.put(name, getDouble(name)); break;

And these new methods:

public Double getDouble(String fieldName) {
    byte[] bytes = getBytes(fieldName);
    return Double.longBitsToDouble(readLong(bytes));
}

protected long readLong(byte[] bytes) {

    long value = 0;
    value += (long) (bytes[7] & 0x000000FF) << 56;
    value += (long) (bytes[6] & 0x000000FF) << 48;
    value += (long) (bytes[5] & 0x000000FF) << 40;
    value += (long) (bytes[4] & 0x000000FF) << 32;
    value += (bytes[3] & 0x000000FF) << 24;
    value += (bytes[2] & 0x000000FF) << 16;
    value += (bytes[1] & 0x000000FF) << 8;
    value += (bytes[0] & 0x000000FF);
    return value;

}

I hope this will help you.

Regards.

IanShaksana commented 4 years ago

i made a small modification to your code in my personal project, i cast all those bytes to long and it works for me thx