Menu

#122 CsvNumber - rounding mode

v1.0 (example)
closed
None
5
2023-11-22
2023-11-09
No

Hi, I noticed that the rounding mode for CsvNumber is HALF_EVEN.
I can't seem to find anyway to change the mode to something else, for instance HALF_UP.

Is it possible to do so or I need to create my own converter for this?

Thanks.

Discussion

  • Scott Conway

    Scott Conway - 2023-11-10

    You will have to create a custom converter for this. This was a use case that was not considered in the original design and would be easier to create a converter than to modify CsvNumber, ConverterNumber, and AbstractMappingStrategy.

     
    👍
    1
  • Andrew Rucker Jones

    Actually, it's not hard at all, I think. I'm working on it. Quick question, though, since I have rarely had the pleasure of rounding numbers: are we talking about while reading or writing CSV files?

     
  • Andrew Rucker Jones

    And one more little question: we're only talkig about BigDecimal, right? I don't see RoundingMode being used anywhere else.

     
  • Andrew Rucker Jones

    I think both of my questions might be irrelevant. I simply pass the rounding mode to DecimalFormat, and what it uses that for isn't that important to me. I've written a test for writing BigDecimals to a CSV output to make certain the rounding mode arrives where it's supposed to be and is applied as advertised, and that test passes.

     
  • Andrew Rucker Jones

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

    This is implemented and will go out with the next release.

     
  • Andrew Rucker Jones

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

    Version 5.9 has been released with this feature.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.