How to add a zero in the last digit of excel file ?
I print below value by code below
DecimalFormat df = new DecimalFormat("#.00");
System.out.println(s.getNetAmount());
System.out.println(df.format(s.getNetAmount()));
and the result was
691.200
691.20
But when I write it into excel file, I expect to get 691.20, but I get 691.2.
This is how I write to excel file
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;
}