Menu

#95 Add annotation for number formating.

closed
None
5
2018-06-04
2018-03-15
No

Hi,

could you please add the possibility to provide a format for floating point numbers (Double)?
There is already an annotation for dates (@CsvDate). Maybe you could come up with another annotation?

Example:

@CsvBindByPosition(position = 6, locale = "de")
@CsvNumber("#0.00")
private Double value;

Currently I solved this by having my own Double-converter and added an annotation that takes the format and the locale as a parameter:

    @CsvCustomBindByPosition(position = 6, converter = CsvCustomDoubleConverter.class)
    @CsvNumberFormat(format = "#0.00000#####", locale = "de")
    private Double value;

Would be great if you would consider to add this feature in a future release.

Cheers,
Patrick

Discussion

  • Andrew Rucker Jones

    • assigned_to: Andrew Rucker Jones
     
  • Andrew Rucker Jones

    Yes, I like this idea. I believe I will be implementing this for version 4.3.

     
  • Scott Conway

    Scott Conway - 2018-03-19

    Hello Patrick - In both Feature Request 94 and 95 you state you have your own solution. Please send us the code because it be the solution or the basis of our solution.

    Thanks in advance.

    Scott :)

    P.S. Please include your unit tests <bg>.</bg>

     
  • Patrick Metz

    Patrick Metz - 2018-03-19

    Hi Scott,

    please find my solution in the attachment. There are also unit tests for the custom converter.

    I did not really test the method convert(String value) in the class CsvCustomDoubleConverter in real life as I just export files and do not write into database.

    Hope this helps...

    Patrick

     
  • Andrew Rucker Jones

    • status: open --> pending
     
  • Andrew Rucker Jones

    I have implemented this feature and it will be released with version 4.2.

     
  • Andrew Rucker Jones

    • status: pending --> closed
     
  • Andrew Rucker Jones

    4.2 has been released.

     
  • Patrick Metz

    Patrick Metz - 2018-06-04

    Great! Just removed my solution from our project and replaced it with yours.

    @CsvBindByPosition(position = 6, locale = "de")
    @CsvNumber(value = "#0.00")
    private Double value;
    

    Thank you very much for your effort!

     

Log in to post a comment.

MongoDB Logo MongoDB