【问题标题】:Remove decimal values in supercsv删除 supercsv 中的十进制值
【发布时间】:2014-10-02 07:14:05
【问题描述】:

我有以下 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,但我不知道如何。

【问题讨论】:

    标签: supercsv


    【解决方案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;
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      相关资源
      最近更新 更多