0

I am using the package org.apache.poi.openxml4j.opc; package to read in an excel file and it is changing the accuracy of the numbers being read from excel.

I have an instance in which if I have 1.11 or 2.22 or 4.44 in a cell then the XSSFWorkbook returns a 1.110000000001, 2.220000000002 and so on. Has anyone got an idea what is going on?

cobie
  • 7,023
  • 11
  • 38
  • 60
  • Which function did you use to get cell value? `cell.get...Value()` – Zaw Than oo Jan 17 '14 at 11:19
  • I am in the process of doing some debugging and after call Workbook.create(inputStream) I inspect the rows from the sheet and can see that the number contained in the rows contains the extraneous zeroes – cobie Jan 17 '14 at 11:23
  • 1
    Check http://stackoverflow.com/a/7100727/624003 and then http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DataFormatter.html – Sankumarsingh Jan 17 '14 at 12:06

1 Answers1

0

I remember having the exact problem as you described here in the past, and I believe the problem stems from Java's precision problem with double. In my workaround, I converted and formatted the double value into String before setting the string value into the cell.

limc
  • 39,366
  • 20
  • 100
  • 145