2

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!

mrbela
  • 4,477
  • 9
  • 44
  • 79
  • possible duplicate of [POI reading excel strings as numeric](http://stackoverflow.com/questions/20430895/poi-reading-excel-strings-as-numeric) – Gagravarr Dec 04 '14 at 17:57

1 Answers1

0

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

Double d = 5.25;
Integer i = d.intValue(); // i becomes 5
szpetip
  • 333
  • 6
  • 12
  • 1
    The problem is that I cut my "real doubles" to ints.. But in these cases I want the whole double value and not only the pre-decimal point positions. I think I have to make a case analysis of the spcific cell type.. :/ only because the toString converts an integer to a double.. that sucks. – mrbela Dec 04 '14 at 16:04