pbnjay / grate

A Go native tabular data extraction package. Currently supports .xls, .xlsx, .csv, .tsv formats.
MIT License
137 stars 22 forks source link

Fixed reading of decimal numbers when they are saved as int #17

Open mbgonicus opened 7 months ago

mbgonicus commented 7 months ago

The xls standard allows to save a decimal number like 1.75 as an integer, multiplied by 100. The current implementation did neither detect this as an integer nor as a float and subsequently returns the default value 0.

This fix adds the case to RKNumber's Float64() method in order to retrieve the value correctly as float.

It also adds a test and a new xls file in testdata for this case. I did not dare to touch the existing xls files to not corrupt the saved data (I only have LibreOffice and it might do funky things). So if you do not like a new file there, please feel free to edit this PR to your liking.

pbnjay commented 7 months ago

Hmm thanks for catching that! I think we should cover the remaining case also, can you add that in?

if (r&1) == 0 && (r&2) != 0 {
    return float64(val)
}
mbgonicus commented 7 months ago

Hmm thanks for catching that! I think we should cover the remaining case also, can you add that in?

if (r&1) == 0 && (r&2) != 0 {
    return float64(val)
}

But that case would mean it is a signed integer and should be handled via the Int() method there? IsInteger() would be true in that case anyway.

mbgonicus commented 7 months ago

@pbnjay btw the failing tests are failing already, i.e. are not failing due to my changes.