Bug 65897 - Reading large number in Excel, precision lost
Summary: Reading large number in Excel, precision lost
Status: RESOLVED INFORMATIONPROVIDED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-18 03:30 UTC by vosamo
Modified: 2022-02-19 11:50 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description vosamo 2022-02-18 03:30:30 UTC
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);

    }