Bug 56317

Summary: While reading excel (.xls) numeric value "0.002877" and its multipes of 2 & 4 and division of 3 it shows 19 decimals insted of 6.
Product: POI Reporter: Benny Kelambeth <kbenny>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED INVALID    
Severity: critical    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Benny Kelambeth 2014-03-26 09:05:45 UTC
The following apache packages used;

--------------
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.*;
import org.apache.log4j.*;
--------------

int lengthBeforeDecimal = decimalVal.substring(0,decimalPos).length();
								//System.out.println("lengthh before decimal:::"+lengthBeforeDecimal);
								//System.out.println("Length after decimal:::"+(actualLength-lengthBeforeDecimal-1));		
								lengthAfterDec=actualLength-lengthBeforeDecimal-1;

The above code is getting 19 decimals for the numeric value: "0.002877" and its multiples of 2 & 4(0.005754, 0.011508) and division by 3(0.000959).

i.e.; for example: "0.002877" is taken as ".0028770000000000002".

Could you please suggest so that only the six decimals are to be read from the xl-sheet.

Thanks & Regards,
Benny J. Kelambeth
Comment 1 Nick Burch 2014-03-26 09:40:55 UTC
That's just how floating point values work

If you want to format a cell as a string, as it looks in Excel, use DataFormatter.formatCellValue(Cell)
Comment 2 Benny Kelambeth 2014-03-26 09:51:49 UTC
Hi,
The issue is that only few of the excel (.xls file) numeric value like: "0.002877", is reading as 19 decimals; how ever if we change the last decimal value like 0.002876 or 0.002878 then it is returning as 6 decimals only.

How can we  read the following values as 6 decimals.
0.002877
0.005754
0.011508
0.000959
...........

Thanks,
Benny