简体   繁体   中英

When reading cell data from excel in java it returns decimal value

I am trying to read values from the excel file. The value in field is 7430031259 , I used the code item_code = cell.toString(); to get the value, but the output is like this 7.430031259E9 . How to solve this?

The best possibility of getting a cell value in apache poi is to use the methods that are meant for this purpose ( toString() of a cell isn't).

That means you should directly receive a numeric cell value if you are expecting it:

double numericValue = cell.getNumericCellValue();

should do what you are trying to achieve.

Check the the JavaDocs of XSSFCell for more useful methods.

For the case you still want to use cell.toString() with a String representation of a numeric value in scientific / exponential notation, you can use a BigDecimal as an intermediate result:

BigDecimal bdItemCode = new BigDecimal(cell.toString());
// get the double value of it
double dblItemCode = bdItemCode.doubleValue();
// or get a String in plain notation
String strItemCode = bdItemCode.toPlainString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM