我试图以精度值 2 舍入小数,但它不起作用。让我知道下面代码中的问题:
CellStyle cs = wb.createCellStyle();
DataFormat df = wb.createDataFormat();
cs.setDataFormat(df.getFormat("0.0"));
for (int i=14;i<rows;i++)
{
Cell y= wb.getSheetAt(0).getRow(i).getCell((short) colValue);
if (y.getCellType() == Cell.CELL_TYPE_STRING) {
} else if (y.getCellType() == Cell.CELL_TYPE_NUMERIC) {
float d=(float) y.getNumericCellValue();
y.setCellStyle(cs);
}
}
最佳答案
像这样使用:
CellStyle cs = wb.createCellStyle();
cs.setDataFormat(wb
.getCreationHelper()
.createDataFormat()
.getFormat("##.##"));
y.setCellStyle(cs);
关于java - 对 apache poi ss 工作簿中的数字进行四舍五入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18797406/