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
You can use BigDecimal
, if you want the exact value that you have in Excel Sheet
: -
BigDecimal bd = new BigDecimal("4256411411");
System.out.println(bd.doubleValue());
// If you are sure that's not a floating point number, then use
System.out.println(bd.longValue());
Prints: -
4.256411411E9
4256411411
You can also use wrapper classes :
Double bd=new Double(4445566622);
System.out.println(bd.longValue());
Outputs -4445566622
i had same problem when i only needed String Data that is "1744949451" but it give "1.744949451E9" so this worked for me
XSSFCell cell = cells.getCell(j);
String value = cell.toString();
if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
//cell.setCellType(XSSFCell.CELL_TYPE_STRING);
value = cell.getRawValue();
}
Log.i("LOG", value + " " + cell.getCellType());
Try the following pattern:
Double dblValue = Double.parseDouble("1.99E+07");
String str = String.format("%.2f", dblValue);
System.out.println(str);
Output:
run:
19900000,00
BUILD SUCCESSFUL (total time: 0 seconds)
You can convert as follows, for example:
new BigDecimal("406770000244E+12").toBigInteger();
You can convert easily with the following methods:
Double.valueOf("9.78313E+2").longValue()
or
BigDecimal bd = new BigDecimal("9.78313E+2");
long val = bd.longValue();
Assuming that the given number is in a String form.