java excel 四位小数_Java读取excel小数点的问题

使用Java读取excel的时候,小数自动转为为不精确的小数点了。

读取excel的代码

public static List readExcel(File file) throws Exception {

//初始化结果集

List dataList = new ArrayList();

//获得Workbook工作薄对象

Workbook workbook = getWorkBook(file);

if (workbook == null)

throw new Exception("读取excel数据失败,workbook build null。");

for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {

//获得当前sheet工作表

Sheet sheet = workbook.getSheetAt(sheetNum);

if (sheet == null)

continue;

if (sheet.getNumMergedRegions() > 0)

setSheetMergedRegionsValue(sheet);

//获得当前sheet的开始行

int firstRowNum = sheet.getFirstRowNum();

//获得当前sheet的结束行

int lastRowNum = sheet.getLastRowNum();

//循环所有行

for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {

//获得当前行

Row row = sheet.getRow(rowNum);

if (row == null)

continue;

//获得当前行的开始列

int firstCellNum = row.getFirstCellNum();

//获得当前行的列数

int lastCellNum = row.getPhysicalNumberOfCells();

String[] cells = new String[row.getPhysicalNumberOfCells()];

//循环当前行

for (int cellNum = firstCellNum; cellNum < lastCellNum; cellNum++) {

if (cellNum < 0)

continue;

Cell cell = row.getCell(cellNum);

if (cell == null)

continue;

cell.setCellType(Cell.CELL_TYPE_STRING);

cells[cellNum] = cell.getStringCellValue();

}

// 如果第一列没有数据,continue掉

if (cells.length > 0 && StringUtils.isBlank(cells[0]))

continue;

dataList.add(cells);

}

}

//workbook.close();

return dataList;

}

excel原始文件

44db264e36c32d4321c5281c901f510b.png

读取后的效果

6945b8a25862e2c232d68ea7dfd8f0d6.png

请教这种怎么解决?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值