Browse Source

修复电话等长数字可能出现科学计数法的问题 #583

pull/592/head
Jiaju Zhuang 5 years ago
parent
commit
ec569824c3
  1. 2
      src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
  2. 3
      src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java

2
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java

@ -27,7 +27,7 @@ public class BooleanNumberConverter implements Converter<Boolean> {
@Override @Override
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (BigDecimal.ONE.equals(cellData.getNumberValue())) { if (BigDecimal.ONE.compareTo(cellData.getNumberValue()) == 0) {
return Boolean.TRUE; return Boolean.TRUE;
} }
return Boolean.FALSE; return Boolean.FALSE;

3
src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java

@ -65,7 +65,8 @@ public class ReadAllConverterDataListener extends AnalysisEventListener<ReadAllC
Assert.assertEquals(data.getStringString(), "测试"); Assert.assertEquals(data.getStringString(), "测试");
Assert.assertEquals(data.getStringError(), "#VALUE!"); Assert.assertEquals(data.getStringError(), "#VALUE!");
Assert.assertEquals(data.getStringNumberDate(), "2020-01-01 01:01:01"); Assert.assertEquals(data.getStringNumberDate(), "2020-01-01 01:01:01");
Assert.assertEquals(data.getStringFormulaNumber(), "2.0"); double doubleStringFormulaNumber = new BigDecimal(data.getStringFormulaNumber()).doubleValue();
Assert.assertEquals(doubleStringFormulaNumber, 2.0, 0.0);
Assert.assertEquals(data.getStringFormulaString(), "1测试"); Assert.assertEquals(data.getStringFormulaString(), "1测试");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }

Loading…
Cancel
Save