2014-10-02 24 views
0

刪除十進制值我具有以下CellProcessor方法在supercsv

private static CellProcessor[] getProcessors() { 

    final CellProcessor[] processors = new CellProcessor[] { 
      new NotNull(), // senderId 
      new NotNull(), // orderId 
      new NotNull(), // execQuantity 
      new NotNull(), // execPrice <~~~~~~~~~~~~ 
      new NotNull(new FmtDate("yyyy-MM-dd")), // deliveryDate 
    }; 

    return processors; 
} 

作爲execPrice是雙,輸出CSV文件包含十進制值。它必須是bean中的雙重類型。編寫csv文件時需要更改它。

如何刪除supercsv中的十進制值(或轉換爲整數)?我認爲我必須在CellProcessor中使用FmtNumber,但我不知道如何。

回答

1
private static CellProcessor[] getProcessors() { 

    DecimalFormat df = new DecimalFormat(); 
    df.applyPattern("#"); 

    final CellProcessor[] processors = new CellProcessor[] { 
      new NotNull(), // senderId 
      new NotNull(), // orderId 
      new NotNull(), // execQuantity 
      new NotNull(new ParseDouble(new FmtNumber(df))), // execPrice <~~~~~~ 
      new NotNull(new FmtDate("yyyy-MM-dd")), // deliveryDate 
    }; 

    return processors; 
} 

上面的代碼在遇到像我這樣的情況的人可能想知道的情況下工作。