Matching Excel's floating point in Java

后端 未结 6 1301
长发绾君心
长发绾君心 2020-12-11 02:06

I have an .xlsx spreadsheet with a single number in the top-left cell of sheet 1.

The Excel UI displays:

-130.98999999999

This is v

6条回答
  •  自闭症患者
    2020-12-11 02:50

    This function should produce the same thing you see in the formula bar:

        private static BigDecimal stringedDouble(Cell cell) {
                BigDecimal result =  new BigDecimal(String.valueOf(cell.getNumericCellValue())).stripTrailingZeros();
                result = result.scale() < 0 ? result.setScale(0) : result;
                return result;
        }
    

提交回复
热议问题