如何在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如何擺脫單元格格式? –