This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Unknown numeric to String

 
Ranch Hand
Posts: 949
10
  • 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: 28328
210
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: 949
10
  • 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: 28328
210
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: 949
10
  • 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
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic