2014-10-02 20 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; 
} 

上面的代码在遇到像我这样的情况的人可能想知道的情况下工作。