Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Unknown numeric to String

 
Ranch Hand
Posts: 191
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using POI to fetch a cell from an Excel Sheet and that is working well.

I determine that the cell contains numeric data but I don't know how it is being represented.  It may be 884312314  OR 34.555 OR 74.23 OR 27.34E6

I need the result to be a String.

I'd like to show the scientific value as a string of numbers without the E.

I can throw away the decimal part but prefer not to round.

If it was always the same input format I could use a Java method or formatting to get to a String.  The trouble is that I wont know the starting format.

What can I do?

Thanks,

Kevin



 
Saloon Keeper
Posts: 24541
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be able to retrieve the cell metadata. That will tell you the data type and the Excel formatting options defined for that cell.
 
kevin Abel
Ranch Hand
Posts: 191
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,
I appreciate your reply.
Is this the type of metadata that your are writing about?

if (currentCell.getCellTypeEnum() == CellType.NUMERIC) {
  //do something
}

Is there a way to get more specific details about the numeric type?

Thanks,

Kevin
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excel doesn't have different types of numeric, just different formats (which would be irrelevant to you if all you want is the value?).

So why don't you use POI to just read the number out using the getNumericCellValue method?
You can then format it as you like.
 
Tim Holloway
Saloon Keeper
Posts: 24541
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the numeric type internal data format is always double, even for integer cell values (int is equivalent to floating-point with an exponent value of 0).  You'd have to get the cell's data format to know the precise display formatting for the value.
 
kevin Abel
Ranch Hand
Posts: 191
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//This code comes from come from StackOverFlow.    



it seems to work when I RUN the script. It is bringing back the numeric data as a string of number characters.

It crashes when I use the DEBUG mode and I don't know why.  I attached the error part in the Attachments.  

Thanks,

Kevin
selenium-error.PNG
[Thumbnail for selenium-error.PNG]
Debugger error
 
reply
    Bookmark Topic Watch Topic
  • New Topic