History | Log In     View a printable version of the current page.  

Issue Details (XML | Word | Printable)

Key: UBA-6961
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Janak Mulani
Reporter: Daniel Grob
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
ULCBase

ULCNumberDataType does not round correctly

Created: 26/Jul/06 11:12 AM   Updated: 23/Jun/08 10:45 AM
Component/s: datatype
Affects Version/s: ULC 6.1
Fix Version/s: UltraLightClient '08

Issue Links:
Duplicate
 
This issue is duplicated by:
UBA-6980 ULCNumberDataType should provide an A... Major Closed


 Description  « Hide
ULCNumberDataType does not round as expected, e.g.
100.5 -> 100
100.6 -> 101
101.5 -> 102

The rounding we learned at school for 100.5 would be 101 and not 100.



 All   Comments   Change History      Sort Order:
Daniel Grob - [26/Jul/06 12:38 PM ]
ULCNumberDataType uses the DecimalFormat class to format the numbers. The DecimalFormat class rounds according to the BigDecimal.ROUND_HALF_EVEN policy. This behavior is hardcoded in the DecimalFormat class and cannot be changed.

Swing's JFormattedTextField behaves the same way.

You should implement a custom data type if you want to round according to a differend rounding policy.



ULC @ UBS - [29/Feb/08 03:05 PM ]
We found that the rounding should be changed, too.
The behaviour could be configured using the following snippet:
We recommend to provide a improved UI class that let it configure with an appropriate setter on the ULC side.

public static class UICustomNumberDataType extends UINumberDataType {
private int fMaxFractionDigits;

public void setMaxFractionDigits(int maxDigits) { fMaxFractionDigits = maxDigits; super.setMaxFractionDigits(maxDigits); }

//this function allows rounding on various number of scale
//see TD 2027
public String convertToString(Object obj, boolean flag) {
if (obj instanceof Number) { BigDecimal bd = new BigDecimal(obj.toString()); bd = bd.setScale(fMaxFractionDigits, BigDecimal.ROUND_HALF_UP); return super.convertToString(bd, flag); } else { return super.convertToString(obj, flag); }
}
}


Daniel Grob - [18/Jun/08 05:16 PM ]
New API:
  • ULCNumberDataType.roundMode property
  • ULCPercentDataType.roundMode property