mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix float bug
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.poi.excel.cell.setters;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.poi.excel.cell.CellSetter;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
|
||||
@@ -26,10 +27,6 @@ public class NumberCellSetter implements CellSetter {
|
||||
public void setValue(Cell cell) {
|
||||
// issue https://gitee.com/dromara/hutool/issues/I43U9G
|
||||
// 避免float到double的精度问题
|
||||
if (value instanceof Float) {
|
||||
cell.setCellValue(value.floatValue());
|
||||
} else {
|
||||
cell.setCellValue(value.doubleValue());
|
||||
}
|
||||
cell.setCellValue(NumberUtil.toDouble(value));
|
||||
}
|
||||
}
|
||||
|
@@ -721,4 +721,16 @@ public class ExcelWriteTest {
|
||||
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeFloatTest(){
|
||||
//issue https://gitee.com/dromara/hutool/issues/I43U9G
|
||||
String path = "d:/test/floatTest.xlsx";
|
||||
FileUtil.del(path);
|
||||
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(path);
|
||||
writer.writeRow(ListUtil.of(22.9f));
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user