JDK-8061673 : Refactor similar code for rounding mode handling in NumberFormat
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2014-10-21
  • Updated: 2023-09-11
  • Resolved: 2023-09-06
Related Reports
Duplicate :  
Relates :  
Description
The handling of certain rounding modes in NumberFormat, say UP and DOWN, has very similar structure. Maintenance of the code would be eased and the code clarified if the similar cases were combined.
Comments
This was fixed in JDK-8314169
06-09-2023

While working on 8039915, I also tested merging completely the 3 HALF_UP,HALF_EVEN, HALF_DOWN cases inside one switch branch. That worked perfectly well and all tests passed. All these three rounding moda have the same behaviour with regards to being above or below the tie. The difference is only happening when exactly on the tie. So the rounding behaviour is mostly the same except when on the tie. Thus it makes much sense to go one step further than 8039915 and merge HALF_EVEN with HALF_UP and HALF_DOWN. That would in addition improve a lot understandability and maintanability. I strongly recommend to merge the 3 HALF_* case to have consistent rounding code throughout all rounding modes. One thing that must be checked however is that the current ending loop of the HALF_EVEN case is not needed at all for all number cases. I checked that for all numbers in the integer magnitude, but not outside and also not when in an exponentiation plus input coming from non float/double values.
27-10-2014

See comments in: http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-September/028872.html
21-10-2014