删除supercsv中的十进制值

时间:2014-10-02 07:14:06

标签: supercsv

我有以下CellProcessor方法

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为Double,因此输出csv文件包含十进制值。它必须是bean中的双重类型。我需要在编写csv文件时更改它。

如何在supercsv中删除十进制值(或转换为整数)?我想我必须在CellProcessor中使用FmtNumber,但我不知道如何。

1 个答案:

答案 0 :(得分: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;
}

以上代码适用于像我这样情况相似的人可能想知道。