2014-10-02 4 views
0

에서 소수 값을 제거 execPrice으로내가 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; 
} 

은 더블, 출력 CSV 파일 소수점 값을 포함합니다. 콩에는 double 형이어야합니다. CSV 파일을 작성할 때 변경해야합니다.

어떻게 supercsv에서 10 진수 값을 제거하거나 정수로 변환합니까? 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; 
} 

위의 코드는 나와 같은 상황에있는 누군가가 알고 싶어하는 경우를 대비하여 작성되었습니다.