如何在excel文件的最后一位数字中添加一个零?在最后一位数中填充零
我打印低于值由下面的代码
DecimalFormat df = new DecimalFormat("#.00");
System.out.println(s.getNetAmount());
System.out.println(df.format(s.getNetAmount()));
,结果是
691.200
691.20
但是,当我把它写到Excel文件,我希望得到691.20,但我得到691.2 。
这是我写excel文件
public void write(List<? extends List> list) throws Exception {
if (list != null) {
try {
writeFile(header(), detail(list.get(0)));
} catch (BatchRunException ex) {
throw new BatchRunException(" Fail..." + ex);
}
}
}
private void writeFile(String header, List<String> detail) throws IOException, BatchRunException {
String fullPath = outputPath + fileNameFormat;
File file = new File(fullPath);
File path = new File(outputPath);
if (!path.exists()) {
path.mkdirs();
}
if (!file.exists()) {
file.createNewFile();
}
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
bw.write(header);
bw.write(NEW_LINE);
for (String s : detail) {
bw.write(s);
bw.write(NEW_LINE);
}
} catch (IOException ex) {
throw new BatchRunException(" Fail..." + ex);
}
}
private String header() {
StringBuilder bf = new StringBuilder();
bf.append("Employee Name").append(SEPERATOR);
bf.append("Amount").append(SEPERATOR);
return bf.toString();
}
private List<String> detail(List<SettlementList> dList) {
List<String> list = new ArrayList();
BigDecimal a = new BigDecimal("0");
for (SettlementList s : dList) {
StringBuilder bf = new StringBuilder();
bf.append(s.Name()).append(SEPERATOR);
bf.append(s.getNetAmount()).append(SEPERATOR); // here the error
list.add(bf.toString());
}
return list;
}
因为过人之处单元格格 –
Excel中使用十进制值的二进制表示,类似到Java的'double'。但是你可以将数字格式添加到单元格中。 –
@PhilippSander如何摆脱单元格格式? –