1

I am trying to round off the decimal number with precisaion value 2, but it is not working. Let me know the problem in my below code:

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);
    }
}  
4

1 に答える 1

1

次のように使用します。

CellStyle cs = wb.createCellStyle();
cs.setDataFormat(wb
  .getCreationHelper()
  .createDataFormat()
  .getFormat("##.##"));
y.setCellStyle(cs);
于 2017-01-06T08:57:52.350 に答える