mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
Excel07SaxReader中,对于小数类型,增加精度判断(issue#IB0EJ9@Gitee)
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.DependencyException;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelDateUtil;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
@@ -264,7 +265,15 @@ public class ExcelSaxUtil {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
return getNumberValue(Double.parseDouble(value), numFmtString);
|
||||
|
||||
// issue#IB0EJ9 可能精度丢失
|
||||
final double number = Double.parseDouble(value);
|
||||
if(false == value.equals(Double.toString(number))){
|
||||
// 精度丢失
|
||||
return NumberUtil.toBigDecimal(value);
|
||||
}
|
||||
|
||||
return getNumberValue(number, numFmtString);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -9,7 +9,7 @@ public class IssueIB0EJ9Test {
|
||||
@Test
|
||||
@Disabled
|
||||
void saxReadTest() {
|
||||
ExcelUtil.readBySax(FileUtil.file("d:/test/bbb.xlsx"), "Sheet1",
|
||||
ExcelUtil.readBySax(FileUtil.file("d:/test/数值型测试.xlsx"), "hcm工资表",
|
||||
(sheetIndex, rowIndex, rowlist) -> Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user