How to print a number greater than 7 digits using poi(2.5) from excel sheet in the console using java
while r开发者_如何学运维etrieving 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.
Easiest way is to use a BigDecimal:
System.out.println("Numeric value: " + new BigDecimal(cell.getNumericCellValue()));
I'd use an instance of DecimalFormat
.
DecimalFormat df = new DecimalFormat("#.00000000");
System.out.print(df.format(cell.getNumericCellValue()));
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
精彩评论