From abb8dcf3c3fb040ef75a61d6b5c3c0f544e3507c Mon Sep 17 00:00:00 2001 From: taojinlong Date: Tue, 25 May 2021 15:32:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=86=E5=88=AB=20Excel=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 12 ++++++++++-- .../dataease/service/dataset/ExtractDataService.java | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index b6540ab380..492af2da79 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -44,6 +44,7 @@ import java.io.*; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.text.MessageFormat; +import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -819,8 +820,15 @@ public class DataSetTableService { } else if (cellTypeEnum.equals(CellType.NUMERIC)) { double d = cell.getNumericCellValue(); try { - String value = String.valueOf(d); - return value.endsWith(".0") ? value.substring(0, value.length() -2):value; + Double value = new Double(d); + double eps = 1e-10; + if(value - Math.floor(value) < eps){ + return value.longValue() + ""; + }else { + NumberFormat nf = NumberFormat.getInstance(); + nf.setGroupingUsed(false); + return nf.format(value); + } } catch (Exception e) { BigDecimal b = new BigDecimal(d); return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + ""; diff --git a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java index fde4cf6ff5..11dd7acf0d 100644 --- a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java +++ b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java @@ -639,7 +639,7 @@ public class ExtractDataService { private static String handleExcelIntColumn = " \t\tif(tmp != null && tmp.endsWith(\".0\")){\n" + " try {\n" + - " Integer.valueOf(tmp.substring(0, tmp.length()-2));\n" + + " Long.valueOf(tmp.substring(0, tmp.length()-2));\n" + " get(Fields.Out, filed).setValue(r, tmp.substring(0, tmp.length()-2));\n" + " get(Fields.Out, filed).getValueMeta().setType(2);\n" + " }catch (Exception e){}\n" +