10

while retrieving the value it is giving in the exponential format for big numbers.

while (cells.hasNext ())
{
HSSFCell cell = cells.next ();

System.out.println ("Cell No.: " + cell.getCellNum ());

/*
 * Now we will get the cell type and display the values
 * accordingly.
 */
switch (cell.getCellType ())
{
 case HSSFCell.CELL_TYPE_NUMERIC :
 {

  // cell type numeric.
  System.out.println ("Numeric value: " + cell.getNumericCellValue());


  break;
 }

it is giving values for the numbers whose digit are greater than 7eg.(12345678) as in exponential.Can u help me to get the value in the same format.

skaffman
  • 398,947
  • 96
  • 818
  • 769
sumit
  • 101
  • 1
  • 3

3 Answers3

6

Easiest way is to use a BigDecimal:

System.out.println("Numeric value: " + new BigDecimal(cell.getNumericCellValue()));
dogbane
  • 266,786
  • 75
  • 396
  • 414
5

I'd use an instance of DecimalFormat.

DecimalFormat df = new DecimalFormat("#.00000000");
System.out.print(df.format(cell.getNumericCellValue()));
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
3

In package org.apache.poi.ss.util is class NumberToTextConverter with static member toText, which can help to represent any number value as string. For example:

String value = NumberToTextConverter.toText(cell.getNumericCellValue());

P.S. I know that since that moment when the question has been asked, there have passed nearly 5 years. But nevertheless I hope that my decision will help someone

Indian
  • 529
  • 1
  • 12
  • 25