JXL api 问题:标准输出显示四舍五入的小数而不是实际数字

JXL api issue: Standard out displays rounded off decimal instead of actual number

当我尝试打印包含小数点后五位数字的单元格中的内容时,该数字会自动四舍五入为 3 d.p。 这是我目前所拥有的:

Cell cellNum = sheet1.getCell(col,row);
            WritableCell cell = sheet1.getWritableCell(col, row); 
            if (cell.getType() == CellType.NUMBER){
                cellNum = sheet1.getCell(col,row);
                NumberFormat fivedps = new NumberFormat("#.#####"); 
                WritableCellFormat cellFormat = new WritableCellFormat(fivedps); 
                cell.setCellFormat(cellFormat);


                String cellContent = cellNum.getContents();
                System.out.print(cellContent + "\t");
            }
            else{
              //  Cell cellNum = sheet1.getCell(col,row);

                String cellContent = cellNum.getContents();
                System.out.print(cellContent + "\t");

检查 Cell 类型后,如果它是数字类型,则将 Cell 转换为 NumberCell 以读取它的值。对于您分享的示例,它应该是这样的:

if (cell.getType() == CellType.NUMBER){
    NumberCell cellNum = (NumberCell) sheet1.getCell(col,row);
    System.out.println(cellNum.getValue()); //this will return a double value 
 }

您可以使用类似的技术通过将 Date 转换为 DateCell 来读取其他值。希望这对您有所帮助!