HSSFCell converts Integer to Double

792 Views Asked by At

I want to read an Excel Sheet and I am using HSSF.

The content of an example row is:

Cell0:  Cell1:
A23456  123

Now I want to read the Cell1 as String "123". HSSF recognizes that 123 is a numeric value (getCellType returns CELL_TYPE_NUMERIC == 0).

If I invoke toString (or getNumericCellValue) it returns both a representation of a doulbe: 123.0

But I only want to have the integer without decimal place.

I would use the String.substring method to cut the ".0" off, but the problem is my Excel Sheet can contain "real doubles" too.. I would cut them too..

Maybe you can help me solving this "problem". Thanks!

1

There are 1 best solutions below

1
On

Do not call toString(), Double has an intValue() method, you can do this:

Double d = 5.25;
Integer i = d.intValue(); // i becomes 5