Daniel Noll wrote: > Takahiro Sasaki wrote: >> I created the HSSFWorkbook with Microsoft Excel. >> The numeric cell value gets converted into the wrong value in the >> resultant HSSFCell in the numeric type. >> The value 0.769 in the file is converted to 0.7689999999999999 by >> LittleEndian in the fillFields(RecordInputStream in) method in >> NumberRecord class. >> If I save the file as a csv file and then save back as a xls file, this >> problem doesn't happen. >> Does any body know what is causing this problem? If this is a known >> bug, is there any work around? > > It's not a bug but a misunderstanding. Floating point numbers will do > this from time to time. The workaround is that if you know you want > three decimal places, you can format it to three decimal places > instead of using String.valueOf/Double.toString. > > Daniel > > Are you sure this is not a bug of POI? This is not a random problem. It always does so for the file. Also I can't enforce the decimal places. Also when I save as CSV and then back to XLS, this doesn't happen.
I debugged a little and figure out that the LittleEndian.getDouble(final byte[] data, final int offset) method returns different long bits value (one last digit is different), 4562254508917369340 (Corrent) and 4605101755772172238 (Wrong), which is pass to the Double to get the double value. I have attached the sample file so that the problem can be reproduced. This file is created with the open office 2 by copying paste cells from the problematic ms excel xp file. Takahiro
poi-test.xls.gz
Description: application/gzip
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
