Converting exponential value in java to a number format

前端 未结 12 1492
旧巷少年郎
旧巷少年郎 2020-12-06 05:47

I am trying to read the values from excel sheet using java. When i type more than 10 letters in a cell in excel it is displaying in exponential form like \"9.78313E+2\". but

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 06:05

    Have to convert the cell into number format before reading the cell value. Below is the code snippet that is used to get the actual value that is in exponential format:

    nextCell.setCellType(XSSFCell.CELL_TYPE_NUMERIC);
    Double doubleValue = nextCell.getNumericCellValue();
    BigDecimal bd = new BigDecimal(doubleValue.toString());
    long lonVal = bd.longValue();
    String phoneNumber = Long.toString(lonVal).trim();
    System.out.print("PhoneNumber " + phoneNumber);
    

    Blog has been wirtten to showcase the actual result.

    Regards, Ankur

提交回复
热议问题