When I tried to read very large number in excel,i found the number lost precision.For example,the number in my excel is '100283710028672000000',i used poi open the excel file and read the number,but it became '100283710028672010000'.But no problem with '100283710028673000000' or '100283710028674000000' or some other numbers.I don't know why.Can you help me? My code as below: ============================ public static void main(String[] args) throws IOException { NumberFormat numberFormat = NumberFormat.getInstance( ); numberFormat.setGroupingUsed(false); String filePath = "D:\\work\\test\\test.xlsx"; InputStream is = new FileInputStream(filePath); XSSFWorkbook wb = new XSSFWorkbook(is); XSSFSheet sheet = wb.getSheetAt(0); Row row = sheet.getRow(0); Cell cell = row.getCell(0); String val = numberFormat.format(cell.getNumericCellValue()); BigDecimal b = new BigDecimal(val); System.out.println(b); }
Please read https://stackoverflow.com/questions/41067328/apache-poi-not-returning-the-proper-value-for-large-numbers-coming-from-excel/41106535 I work around this issue by using https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/DataFormatter.html#formatCellValue-org.apache.poi.ss.usermodel.Cell-
https://poi.apache.org/apidocs/dev/org/apache/poi/ss/util/NumberToTextConverter.html is also useful