jxl读取excel浮点数据时,小数点后三位截取问题

  今天导入Excel数据时,发现很多浮点数据被自动四舍五入只保留了三位,原来是jxl里对getContents()进行了封装,对数值型数据作了该处理。一般我们会对读取excel的一整套流程作为工具类,那么在读取单元格数据时,应该将数据分成三类(一般情况):日期,数值,普通字符串。最后统一转换成字符串类型。

     如果是日期类型,可以使用DateCell对象提供的方法:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Cell cell = sheet.getCell(j, i);
DateCell dateCell
= (DateCell) cell; String date = sdf.format(dateCell.getDate());

  如果是数值类型,可以使用NumberCell对象提供的方法:

Cell cell = sheet.getCell(j, i);
NumberCell numberCell = (NumberCell)cell; Double numberValue = numberCell.getValue(); String number = numberValue.toString();
原文地址:https://www.cnblogs.com/pengineer/p/4200612.html