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

Problem reading Double solved #46

Open
hermobass opened this issue Jun 14, 2018 · 1 comment
Open

Problem reading Double solved #46

hermobass opened this issue Jun 14, 2018 · 1 comment

Comments

@hermobass
Copy link

hermobass commented Jun 14, 2018

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
Copy link

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

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

2 participants