Bug 62217

Summary: While reading a cell from Spreadsheet the precision is changed from 10 to 6 digits after decimal in 3.17
Product: POI Reporter: Mayur Jain <mayur.anchalia>
Component: SS CommonAssignee: POI Developers List <dev>
Status: RESOLVED WONTFIX    
Severity: regression CC: nayakpiyushkumar
Priority: P2 Keywords: FAQ
Version: 3.17-FINAL   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Mayur Jain 2018-03-24 09:20:17 UTC
While reading a cell from Spreadsheet the precision is changed from 10 to 6 digits after decimal in 3.17 version

org.apache.poi.ss.usermodel.DataFormatter dataFormatter = new DataFormatter();

String content = dataFormatter .formatCellValue(Cell);

Value in the spreadsheet is 1290.219821387213
Earlier version 3.12 value returned is 1290.2198213872 but the precision is reduced to 6 digits after decimal in latest version to 1290.219821
Comment 1 chenlin 2020-07-11 06:50:53 UTC
The getformat() method of the DataFormatter of the 3.12 version directly obtains the Format class. 

The getformat() function in the dataFormatter of the 3.17 version is changed, and a new ExcelGeneralNumberFormat class is returned. 
The implementation in dataFormatter.formatCellValue() is implemented by the getformat() method in the ExcelGeneralNumberFormat class. 
The TO_10_SF constant is used to limit the data length. This restriction does not exist in the 3.12 version. It can be considered as a version difference. 

This is the code segment where you feel the precision is faulty: 
private static final MathContext TO_10_SF = new MathContext(10, RoundingMode.HALF_UP); 
final double rounded = new BigDecimal(value).round(TO_10_SF).doubleValue();
Comment 2 PJ Fanning 2020-07-11 17:28:06 UTC
The DataFormatter is configurable. Excel stores numbers in floating point format so you need to format the numbers to get a value that matches expectation.

We will not revert to the behaviour in 3.12, a release from 5 years ago. Most users are used to the current behaviour.