Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

dertermine if an excel cell contains a decimal - apache poi

807605Jul 13 2007 — edited Jul 14 2007
This seems so simple, I am so frustrated...

The short:
I'm reading values from excel, and printing to xml, which works fine.

The problem is with decimals.
Some cells are values like 1,15,27
others have values like 115.0,183.5 etc.

The problem is that HSSF reads all number cells as doubles by default. in the past i used a simple (int) to turn it into an integer.

Now, if there is a .0, I need to preserve it, otherwise i just want the integer value.

heres what i have
	// if value in cell has ., respect it
						// otherwise just get int.
						String angry=String.valueOf(currentRow.getCell((short) (columnNumber)).getNumericCellValue());
						if(angry.contains(".")){
						result[col]=String.valueOf((double)(currentRow.getCell((short) (columnNumber)).getNumericCellValue()));
						}else{
							result[col]=String.valueOf((currentRow.getCell((short) (columnNumber)).getNumericCellValue()));							
						}
problem with that is all numbers pulled will be doubles(have the decimal) even if that is not how they are in excel.

So how can I examine the contents of the cell, without converting it to a string.

thank you so much!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 11 2007
Added on Jul 13 2007
2 comments
1,844 views